def test_decode_img(img, wm): rs = RSCoder(255, 223) msg_str = img_to_str(wm) msg = msg_to_bin(msg_str) LL, LH, HL, HH = dwt(img) HH = np.ravel(HH) bin_msg = "" for i in range(0, len(msg) / 2): hh_bin = bin(int(round(HH[i]))) hh_bin = hh_bin[hh_bin.index('b') + 1:] bit_pairs = hh_bin[len(hh_bin) - 2:] if len(hh_bin) >= 2 else '0' + hh_bin bin_msg += bit_pairs msg_str = "" for i in range(0, len(bin_msg), 8): digit = bin_msg[i:i + 8] msg_str += unichr(int(digit, 2)) decoded = "" #11475 for i in range(0, len(msg_str), 255): decoded += rs.decode(msg_str[i:i + 255]) dc_list = list(decoded) print(len(dc_list)) for i in range(0, len(dc_list)): dc_list[i] = ord(dc_list[i]) result = dc_list[:wm.size] result = np.reshape(result, wm.shape) return result
def getprotected(self, data): c = RSCoder(255, 127) return c.decode(data)