The method used for error prediction
1. Median Predictor
Use the median predictor MED (Median Edge Detector) to predict the predicted value px of x for the three adjacent pixels on the left, upper and upper left of x in the figure.
2. The bitmap generated according to the prediction error (Location binary map)
Bitmap (Location binary map) can be understood as a map that records the wrong location/a map that can find the predicted wrong location.
The bitmap here marks the prediction error of the first two MSBs of the original value x and the predicted value px.
In mathematical terms, it is:
![](https://img-blog.csdnimg.cn/69fb83df159e43618d9c025481dc4a6f.png)
Then check to see if
it is equal, if it is the same, the bitmap is marked as 0, otherwise it is marked as 1.
Two-image encryption principle
1. Image encryption principle
For a single pixel:
The pixel location is (i, j).
First convert the pixels in the range 0 to 255 to binary. Mathematically, it is:
![](https://img-blog.csdnimg.cn/8b294786d1374ffba7c7a2cef03f2d98.png)
Then use the encryption key to generate a pseudo-random sequence , and the length can be calculated. For a single-channel grayscale image of size (M, N), the length of the random sequence is
.
Execute XOR with the encrypted sequence and the image to obtain the encrypted image .
![](https://img-blog.csdnimg.cn/176570fa065148b09fcd6c9321a3b61d.png)
It goes without saying that the decimal representation of the encrypted image can be calculated.
2. It is recommended to use Logistic chaotic encryption for beginners
Paste the code directly:
def crypt(im, miu, x0):
'''
logistic混沌加密
:param im: 待加密图像
:param miu: μ参数
:param x0: x0参数
:return: 返回密文图像
'''
h, w = im.shape
c_ = np.zeros_like(im)
c_[0][0] = x0
c=[]
c.append(x0)
result = np.zeros_like(im)
result[0][0] = (x0 * pow(2, 48)) % 256
for x in range(1, h * w):
i = x // w
j = x % w
c.append(miu * c[x - 1] * (1 - c[x - 1]))
c_[i][j] = (c[x] * pow(2, 48)) % 256
for i in range(h):
for j in range(w):
result[i][j] = im[i][j] ^ c_[i][j]
return result
Just a few things to note :
To ensure the encryption effect, the miu parameter and x0 parameter must be in the following range:
①
②
Three-embedded block principle and error labeling method
Because the image compresses information in a predictive way, the easiest way to think of it is to embed information where the prediction is correct, mark errors where the prediction is wrong, and wait for the algorithm to process, so that the subsequent non-destructive restoration of the image can be carried out. For the identification of the boundary position between the correct part and the wrong part, the block method can be used to deal with it. In fact, this article does just that.
Blocking: The scanning order is from left to right and from top to bottom, and 4 pixels form a group during scanning.
Error mark: If there is a prediction error, the block before and after the error position will be processed, and the 8 MSBs of the 4 pixels in the front and back blocks will be set to 1, as shown in the figure:
In this way, when encountering the same block, the probability of error is .
Four embedding process
Encrypt with the image encryption key to obtain an encrypted image
, in which each pixel is
, and then determine whether it is an embeddable block according to the tags in the bitmap, and if it is embeddable, embed the 8 MSBs of 4 pixels in the block. The embedded formula is as follows:
Note that the first row and column do not embed information since we used a median predictor.
V. Information Extraction and Image Lossless Restoration
3 situations:
1. Only the image encryption key , you can only restore the image losslessly
First, use the image encryption key to generate a decryption sequence, and then perform an XOR operation with the image bit by bit. In short, it operates according to the principle of image encryption. The specific mathematical formula is as follows:
![](https://img-blog.csdnimg.cn/f623815a9e1e49bc8eddda2dcbea1ad3.png)
Compared to the original image, only the embedded secret information and mislabeled places will be different.
The part of embedding secret information, since it can be embedded, naturally there is no prediction error, just embed its 2-bit MSB directly according to the result of median prediction.
If the wrong place is marked, just make changes according to the marked situation.
2. Only information hiding key , then you can only extract secret information
Scan all the pixels except the first row and the first column by block, and then identify the error according to the principle of error marking, and extract the rest as secret information.
Then process the extracted information with your existing information hiding key to get the secret information which can be read after decryption.
3. If you have two keys ,
you can restore the image without loss and extract the complete secret information. Refer to the above for specific steps.