在灰度图像的最低有效图像位中隐藏消息

Hide a message in the least significant image bit of a greyscale image

我需要读入来自用户的消息,遍历消息的每一位并用每个消息位覆盖最低有效图像位。

我目前有一个程序可以遍历每个图像像素并重写图像。

那么如何读取最低有效图像位以及如何获取每个消息位。

这是使用 python 3.x

的灰度图像
from PIL import Image

import numpy as np
import bitget
import scipy.misc as smp

im = Image.open("catBlack.png") #Can be many different formats.
pix = im.load()
print (im.size )#Get the width and hight of the image for iterating over
print (pix[1,1]) #Get the RGBA Value of the a pixel of an image
#pix[x,y] = value # Set the RGBA Value of the image (tup


data = np.zeros( (im.size[0],im.size[1],2), dtype=np.uint8 )

for i in range (im.size[0]):
    for j in range (im.size[1]):
        print (i,j)
        data[i,j] = pix[i,j]

im = Image.fromarray(data)
im.save("GreyCat.png")

此外,我将如何解码此消息

干杯帮助

阅读消息后,您可以将其转换为 ascii 码(ascii 范围在 0 到 127 之间),即您需要最大。 7位代表字母

灰度值可以从 0 到 255,每个像素有 8 位,因此您可以使用 4 个像素的最后 2 位来表示一个字。

例如你想传输 hi

h-73的ascii码 73 的二进制 - 1001001 i - 74 的 ascii 码 i的ascii码-1001010

  • 现在您将像您提到的那样遍历每个像素
  • 读取像素的颜色值转换成二进制

假设颜色值为

第一个像素为 1111111
0101010 第二
第三名 1100110
1111111 第四个
0001111 第五次
第六名 1011111
第七名 1100110
第八名 1110001
1111111 第九次
第十名 1010101

首先我们必须传输 h (01001001) 因此我们将更改 4 个像素的最后两位 颜色的新值将是这样的

第一个像素为 1111101
0101000 第二
第三名 1100110
1111101 第四个

现在我 (01001010) 的值将像

第五名0001101
第六名 1011100
第七名 1100110
第八名 1110010

现在我们将把剩余像素的最后一位更改为全零
第九个 1111100
第十名 1010100