我正在尝试通过numpy数组编写LSB隐写术方法。我得到了制作布尔索引掩码的代码,它将给出那些红色通道的位,需要与1异或。你知道吗
import numpy as np
from scipy.misc import imread
import matplotlib.pyplot as plt
message = 'Hello, World!'
message_bits = np.array(map(bool, map(int, (''.join(map('{:b}'.format, bytearray(message)))))), dtype=np.bool)
img = imread('screenshot.png')
xor_mask = np.zeros_like(img, dtype=np.bool)
ind = 0
for j, line in enumerate(xor_mask):
for i, column in enumerate(line):
if ind < len(message_bits):
xor_mask[j, i, 0] = message_bits[ind]
ind += 1
else:
break
else:
continue
break
img[xor_mask] ^= 1
有没有更紧凑的方法来构造xor\u掩码?也许通过numpy广播
升级版本: 将我的for循环简化为:
for j, line in enumerate(xor_mask):
if ind < len(message_bits):
xor_mask[j, :, 0] = message_bits[ind]
ind += len(xor_mask[j])
else:
break
如果填充
message_bits
使元素的数量与xor_mask
中像素的数量相同,那么就变得简单了:另一种方式,无填充:
相关问题 更多 >
编程相关推荐