【发布时间】:2017-02-20 18:48:03
【问题描述】:
我正在尝试通过 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_mask?也许通过 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
【问题讨论】:
标签: python numpy optimization scipy steganography