天天看點

資訊隐藏 低4位替換

所謂直接4bit 替換法, 就是直接用秘密圖像像素值的高4bit 去替換載體圖像像素值的低4bit。由于低4bit通常為噪聲,對圖檔影響不大

載體圖檔:

資訊隐藏 低4位替換

待隐藏圖檔

資訊隐藏 低4位替換

嵌入代碼

import numpy as np
import cv2

tar_path='target.jpg'
back_path='background.jpg'

tar=cv2.imread(tar_path)
back=cv2.imread(back_path)
x,y,z=back.shape

print(x,y,z)
print(back.shape)
print(tar.shape)
tar=cv2.resize(tar,(y,x))
print(tar.shape)
b,g,r=cv2.split(back)
np_back=[b,g,r]
np_back=np.array(np_back)
#print(np_back[0].shape)
b,g,r=cv2.split(tar)
np_tar=[b,g,r]
np_tar=np.array(np_tar)

np_tar1=np_tar//16

np_back=np_back//16
np_back=np_back.astype(np.uint8)
np_back=np_back*16
result_high=np_back+np_tar1
#result_low=np_back+np_tar2

cv2.imwrite('result.jpg',cv2.merge(result_high))
           

提取代碼

src_path1='result.jpg'
src1=cv2.imread(src_path1)
b,g,r=cv2.split(src1)
np_src_high=np.array([b,g,r])
np_src_high=(np_src_high%16)*16
img_high=cv2.merge(np_src_high)
cv2.imwrite("recover.jpg",img_high)

           

嵌入後圖檔

資訊隐藏 低4位替換

讀取後圖檔

資訊隐藏 低4位替換