Chapter 5 - Digital Watermarking - 1 - Bit Plane

Digital watermark concept

Digital watermarking is a technology that embeds specific digital information into digital works to realize functions such as information hiding, copyright authentication, integrity authentication, and digital signature.

Take image watermark as an example:

Watermark embedding process: copyright information watermark A is embedded in image B, and image C containing watermark is obtained. Image C and image B are basically the same in appearance, and the difference cannot be distinguished by naked eyes.

Watermark extraction process: through the watermark extraction technology, the watermark in the image C is extracted to obtain the deleted watermark D and the extracted watermark E. The image C should be basically the same as the image D in appearance, and at the same time cannot be distinguished by the naked eye. In addition, the watermark E should be the same as the image D. Watermark A is consistent.

Similarly, in order to ensure that the naked eye cannot observe the difference before and after embedding the watermark, it must be ensured that the embedded watermark has little impact on the carrier, which requires that the embedding position be hidden in a relatively unimportant position.

And as we know, in a multi-digit decimal number, modifying the high-order value has a greater impact on the value than modifying the low-order value. Similarly, modify the lowest bit of the carrier image pixel to realize the embedding of the watermark , with minimal impact on the carrier image. This extends a new concept - bit plane.

bit plane

Extract the value of the same bit in the binary form of all pixels in the grayscale image to obtain a binary image, which is called a bitplane of the grayscale image, and the process of other bitplanes becomes the bitplane break down.

Any x ∈ [0,255] satisfies x = a8 * 2^7 + a7 * 2^6 + a6 * 2^5 + a5 * 2^4 + a4 * 2^3 + a3 * 2^2 + a2 * 2^ 1 + a1 * 2^0 , where a1, a2, a3, a4, a5, a6, a7, a8 are equal to 0 or 1.

The bitmap decomposition is to take out all a1, a2, a3, a4, a5, a6, a7, a8 of the values ​​of all pixels into an independent array, these arrays are bit planes, and the extracted bit plane is a binary value picture. Involving bit-bit operations, the key operation is of course AND operation.

In addition, when displaying bit planes, the bit planes whose lower bits are fetched tend to be black. The specific operation is that when the pixel point of the bit plane RD is greater than 0 (with value), it is set to true, and the position equal to 0 is set to false to form a template mask, and then the position of the template position is set to 255, as follows:

mask = ( RD > 0 )

RD[ mask ] = 255

After simplification: RD[ RD > 0 ] = 255

The bit plane code to get the image is as follows:

import cv2 as cv
import numpy as np

# 读取原始图
lena = cv.imread("lena.png", 0)
cv.imshow("lena", lena)

r, c = lena.shape
# 获取位平面当然是用比特位与运算
# 8个位平面对应需要8个与图像等宽高的矩阵
x = np.zeros((r, c, 8), dtype=np.uint8)
for i in range(8):
    x[:, :, i] = 2 ** i  # 每个矩阵填充做与运算的数值
    # cv.imshow(str(i),x[:,:,i])#为什么后面要做阈值处理,这里可以看出,只有6,7稍微白一些,0-5都挺黑的

# 用来保存位平面结果的数组
result_images = np.zeros((r, c, 8), dtype=np.uint8)
for i in range(8):
    # 原图和矩阵进行与运算,并把结果保存好
    result_images[:, :, i] = cv.bitwise_and(lena, x[:, :, i])  # 与运算后得到一个灰度图(里面只有0和位值)

    mask = result_images[:, :, i] > 0  # 灰度图中值大于0的位置为true,等于0的位置为false,得到一个掩模
    result_images[mask] = 255  # 根据掩模进行处理,灰度图变成了二值图
    cv.imshow(str(i), result_images[:, :, i])

cv.waitKey()
cv.destroyAllWindows()

The program runs as follows:

If the mask processing step is removed, the operation effect is as follows:

Summary: The high-level bit plane is more similar to the original image, and has a greater impact on the original image, but the low-level bit plane can round the details of the high-level bit plane, making the image more full and vivid.

Guess you like

Origin blog.csdn.net/sunguanyong/article/details/130274734