# An Adaptive Reversible Data Hiding Scheme Using AMBTC and Quantization Level Difference
## 3 The Proposed Scheme
### Extraction and Recovery Phase  
The processes for the extraction and recovery phases are shown in Figure 6. S will be extracted from modified image \(I^{\prime}\). When the block \(b_{i}\) belongs to a non-embedding case, there are only two values in it. Therefore, we do not need any extra information to record whether this block has secret data or not.  
Input: Modified image \(I^{\prime}\).  
Output: Secret data S and the cover image I.  
Step 1. Divide \(I^{\prime}\) into \(k\times k\) non-overlapping blocks \(b^{\prime}_{i}\)'s.  
Step 2. Calculate the frequency f of the number of different pixels in the current processing block \(b^{\prime}_{i}\). The Algorithm 2 is described as follows.  
```
Output: Frequency \(f\) for\(i=0\) to \(k\times k-1\). do  if \(p^{\prime}_{i+1}\
eq p^{\prime}_{0,1,\ldots,j}\). then \(f=f+1\); endif \(j\)++; endfor
```  
**Algorithm 2** Procedure for calculating the frequency.  
Step 3. Determine the value of \(f\). If \(f>2\), go to step 4. Otherwise, go back to Step 2.  
Step 4. Sort all \(p^{\prime}_{n}\)'s in the block \(b^{\prime}_{i}\) in ascending order. The first and last values in the sorted sequence are \(l_{i}\) and \(h_{i}\), respectively. And the positions of \(l_{i}\) and \(h_{i}\) are \(r_{1}\) and \(r_{2}\), respectively.  
Step 5. Compute the values of \(d_{i}\) and \(a_{i}\) utilizing Equations (6) and (7), respectively. Extract the secret data from \(p^{\prime}_{n}\)'s using Equation (10).  
\[M_{n}=\left\{\begin{array}{l}h_{i}-p^{\prime}_{n},\text{ if }p^{\prime}_{n}> \frac{l_{i}+\frac{h_{i}}{2}}{\text{and }n\
eq r_{1}\text{ or }r_{2}}\\ p^{\prime}_{n}-l_{i},\text{ if }p^{\prime}_{n}<\frac{l_{i}+\frac{h_{i}}{2}}{ \text{and }n\
eq r_{1}\text{ or }r_{2}}\end{array}\right.. \tag{10}\]  
Then, convert \(M_{n}\) into \(a_{i}\) secret bits and add in S.  
Step 6. Recover block \(b^{\prime}_{i}\) using Equation (11).  
\[p_{n}=\left\{\begin{array}{l}h_{i},\text{ if }p^{\prime}_{n}>\frac{l_{i}+h_{i} }{2}\\ l_{i},\text{ if }p^{\prime}_{n}<\frac{l_{i}+\frac{h_{i}}{2}}{ \text{.}}\end{array}\right.. \tag{11}\]  
Step 7. Repeat Step 2 to Step 6 until all modified blocks \(b^{\prime}_{i}\)'s are processed.  
Step 8. Obtain the cover image I and secret data S.  
After all steps are computed, we can extract S from modified block \(b^{\prime}_{i}\) and recover each \(b^{\prime}_{i}\) using \(\min\{p^{\prime}_{n}\}\) and \(\max\{p^{\prime}_{n}\}\) after sorting. We used \(l_{i}\) and \(h_{i}\) to replace the positions of FL and LH, respectively. This allows us to know \(l_{i}\) and \(h_{i}\) utilizing the ascending order of all \(p^{\prime}_{n}\)'s in modified block \(b^{\prime}_{i}\) while extracting. This approach can avoid the problem when the value of \(M_{n}\) is 0. We also provide a detailed example of the extraction and recovery phases in Figure 7. In Figure 7, (a) presents the modified block \(b^{\prime}_{i}\) that follows the previous example in Figure 5, (b) shows the results of extracted \(M_{n}\) and S in binary form and (c) is the resulting block \(b_{i}\) after recovery. Firstly, calculate the frequency f and determine whether the value of f is greater than 2. Then, all \(p^{\prime}_{n}\)'s in the modified block \(b^{\prime}_{i}\) will be sorted in ascending order. The first and last values are \(l_{i}\) and \(h_{i}\), respectively. According to the first and last values in a sorted sequence corresponding positions in modified block \(b^{\prime}_{i}\), the positions of \(r_{1}\) and \(r_{2}\) are 1 and 14, respectively. Next step, \(M_{n}\) will be extracted from modified block \(b^{\prime}_{i}\) using Equation (8). Each \(M_{n}\) will be converted into \(a_{i}\) secret bits and added in the S. In the last step, recover each \(p^{\prime}_{n}\) using Equation (9). Finally, we can get block \(b_{i}\) and extract S from the modified block \(b^{\prime}_{i}\).