【发布时间】:2021-07-23 08:27:54
【问题描述】:
我目前正在设计一种隐写术系统,该系统使用 Python 和 OpenCV 库使用多种技术(K-means、Canny 边缘检测)检测图像中的某个区域。 我在更新图像像素值以在最低有效位中包含我的秘密数据时面临一个巨大的问题。
我开始在几次计算后找到阈值。
thresh = cv.adaptiveThreshold(imgray,100,cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY_INV,11,2)
为了测试该区域,我做了以下操作:
Testim=np.copy(originalImage)
Testim[thresh==0]=[0,255,0]
plt.imshow(Testim)
plt.show()
它显示了这张图片,表明我要循环的区域:
Image showing after the threshold Isolation in green
在那之后,我经历了一个循环,我将向您展示它的 sn-p,它迭代 RGB 值并用秘密数据中的一个位更改每个最低有效位。我要注意的是,原始图像形状是 (1024,1024,3) 并且图像[thresh==0] 的形状是 (863843, 3) :
for i in range(image[thresh==0].shape[0]):
# convert RGB values to binary format
r, g, b = to_bin(image[thresh==0][i])
# modify the least significant bit only if there is still data to store
if data_index < data_len:
# least significant red pixel bit
image[thresh==0][i][0] =int (r[:-1] + binary_secret_data[data_index], 2)
data_index += 1
if data_index < data_len:
# least significant green pixel bit
image[thresh==0][i][1] = int (g[:-1] + binary_secret_data[data_index], 2)
data_index += 1
if data_index < data_len:
# least significant blue pixel bit
image[thresh==0][i][2] = int (b[:-1] + binary_secret_data[data_index], 2)
data_index += 1
# if data is encoded, just break out of the loop
if data_index >= data_len:
plt.imshow(image)
break
return image,thresh
问题是RGB的值在循环内外根本没有变化,我添加了一些打印语句,它一直显示为零,我还尝试显式分配1,它也不起作用.
我想指出,这只是编码功能的一部分
感谢您的帮助
【问题讨论】:
-
如果您将结果保存为 JPEG,由于有损压缩,最后几位将不一致。
-
我在 png 上试过了,它也不起作用
-
您真的在计算
image[thresh==0]数百万次吗?为什么不把它放在一个单独的变量中? -
“我添加了一些打印语句,它一直显示为零” 您添加了哪些打印语句?你可以再详细一点吗?最好理解您为什么认为这里的
image没有被修改。
标签: python opencv image-processing image-segmentation steganography