示例#1
0
def main(file_name):
    a = ReversibleDataHiding()
    root_path = pu.get_root_path()
    file_path = pu.path_join(root_path, pu.INPUT_PATH, file_name)

    gray_lena = iu.read_img(file_path, iu.READ_GRAY)
    # changed_gray_lena = gray_lena.copy()
    # changed_gray_lena[100, 100] = 0

    # a.encrypt(gray_lena, 0b11111000001111100000)
    # a.decrypt()

    # print("1")
    print("encrypting!")
    print("insert data: 0b11111000001111100000")
    a.encrypt(gray_lena, 0b11111000001111100000)
    # print("2")
    print("decrypting!")
    a.decrypt()
    # print("3")
    # a.encrypt(changed_gray_lena, 0b11111000001111100000, pth="static/test/changed")
    # print("4")
    # a.decrypt(pth="static/test/changed")
    print("extract data: ", end="")
    print(a.r.data)
    print(f"hide data max length: {a.e.max_length()}")
    print(f"image size: {gray_lena.shape}")
    # print(a.r.data)
    print("file save in /static/integral!")
示例#2
0
def main(file_name="200px-Lenna.jpg"):
    root_path = pu.get_root_path()
    # file_name = "trees.png"
    file_path = pu.path_join(root_path, pu.INPUT_PATH, file_name)

    color_lena = iu.read_img(file_path, iu.READ_COLOR)

    r_data = 0b11111000001111100000
    g_data = 0b11111111110000000000
    b_data = 0b10101010101010101010

    length = [len(bin(r_data)), len(bin(g_data)), len(bin(b_data))]
    tplt = "{0:<" + str(length[0]) + "}\t{1:<" + str(length[1]) + "}\t{2:<" + str(length[2]) + "}"

    print(tplt.format("r_data(insert):", "g_data(insert):", "b_data(insert):"))
    print(tplt.format(bin(r_data), bin(g_data), bin(b_data)))

    r = ReversibleDataHidingRGBA()
    r.encrypt(color_lena, r_data, g_data, b_data)
    # iu.print_img(r.encrypted)

    # encrypted = iu.read_img(pu.path_join(root_path, "static", "integral_rgba", "image.png"), cv2.IMREAD_UNCHANGED)
    r.decrypt(r.encrypted)
    # iu.print_img(r.decrypted)
    print(tplt.format("r_data(extract):", "g_data(extract):", "b_data(extract):"))
    print(tplt.format(r.r_data, r.g_data, r.b_data))
    print(f"max length of hide data: {r.max_length}")
    print(f"image size: {color_lena.shape}")
    print("file save in /static/integral_rgba!")
示例#3
0
    def decrypt(self, img=None, LM=None, LM_encrypted=True, pth=__INTEGRAL_PATH):
        """

        Args:
            img: 需要解密的图像
            LM: 保存有LM图像
            LM_encrypted: LM是否需要解密
            pth: 保存的路径

        Returns:

        """
        if img is None:
            img = iu.read_img(pu.path_join(self.root_path, pth, "image.png"))
        if LM is None:
            LM = iu.read_img(pu.path_join(self.root_path, pth, "LM.png"))
        r = Receiver(img, LM, LM_encrypted)
        r.decryption()
        r.data_extraction(self.data_length)
        r.recomposition()
        iu.save_img(r.res_img, pu.path_join(self.root_path, pth, "res.png"))
        self.decrypted = r.res_img
        self.r = r
示例#4
0
    g1 = img1[:, :, 1]
    r1 = img1[:, :, 2]
    b2 = img2[:, :, 0]
    g2 = img2[:, :, 1]
    r2 = img2[:, :, 2]
    r = np.array([0, 0, 0])
    g = np.array([0, 0, 0])
    b = np.array([0, 0, 0])
    r[0] = ssim(r1, r2)
    r[1] = mse(r1, r2)
    r[2] = psnr(r1, r2)
    g[0] = ssim(g1, g2)
    g[1] = mse(g1, g2)
    g[2] = psnr(g1, g2)
    b[0] = ssim(b1, b2)
    b[1] = mse(b1, b2)
    b[2] = psnr(b1, b2)
    return np.mean(r + g + b)


if __name__ == "__main__":
    root_path = pu.get_root_path()
    img1 = iu.read_img(pu.path_join(root_path, "static/input/timg.jpeg"),
                       iu.READ_GRAY)
    img2 = iu.read_img(
        pu.path_join(root_path, "static/test/unchanged/res.png"), iu.READ_GRAY)

    print(ssim(img1, img2))
    print(mse(img1, img2))
    print(psnr(img1, img2))
示例#5
0
    r1 = img1[:, :, 2]
    b2 = img2[:, :, 0]
    g2 = img2[:, :, 1]
    r2 = img2[:, :, 2]
    r = np.array([0, 0, 0, 0, 0])
    g = np.array([0, 0, 0, 0, 0])
    b = np.array([0, 0, 0, 0, 0])
    r[0], r[1] = npcr_uaci_analysis(r1, r2)
    g[0], g[1] = npcr_uaci_analysis(g1, g2)
    b[0], b[1] = npcr_uaci_analysis(b1, b2)
    r[2] = ent_analysis(r2)
    g[2] = ent_analysis(g2)
    b[2] = ent_analysis(b2)
    r[3], r[4] = cor_analysis(r1, r2)
    g[3], g[4] = cor_analysis(g1, g2)
    b[3], b[4] = cor_analysis(b1, b2)
    return np.mean(r + g + b)


if __name__ == "__main__":
    root_path = pu.get_root_path()
    img1 = iu.read_img(
        pu.path_join(root_path, "static/test/unchanged/image.png"),
        iu.READ_GRAY)
    img2 = iu.read_img(
        pu.path_join(root_path, "static/test/changed/image.png"), iu.READ_GRAY)

    print(npcr_uaci_analysis(img1, img2))
    print(ent_analysis(img2))
    print(cor_analysis(img1, img2))
示例#6
0
    e.data_hider(0b11000100000110001111111011100001000001100011111110111000010000011000111111101110000100000110001111111011)
    e.encryption()
    root_path = pu.get_root_path()
    out = pu.path_join(root_path, pu.OUTPUT_PATH)
    e.save(out)
    # lm = dec.decryptioner(e.encrypted_LM, dec.secretKey, 256)
    # diff = e.LM.astype(np.int) - lm.astype(np.int)
    # i = dec.decryptioner(e.encrypted_I, dec.secretKey, 256)
    # diff_I = i - e.res_img
    # print(np.sum(abs(diff)))
    # print(np.sum(abs(diff_I)))
    # iu.print_imgs(e.ans.astype(np.uint8), e.encrypted_LM.astype(np.uint8))
    pass


if __name__ == '__main__':
    root_path = pu.get_root_path()
    file_name = "200px-Lenna.jpg"
    file_path = pu.path_join(root_path, pu.INPUT_PATH, file_name)

    gray_lena = iu.read_img(file_path, iu.READ_GRAY)
    #
    # e1 = Encryptor(gray_lena, Encryptor.predict_method1)
    # e1.decomposition()
    # e1.predict()
    #
    # print(e1.error())

    # iu.print_imgs(e1.recomposition())
    __test(gray_lena)
示例#7
0
    for i in range(0, 4):
        P = permutation(P, init_matixs[i], M, N)
        P = row_diffusion(P, init_matixs[i], F, M, N)
        P = column_diffusion(P, init_matixs[i], F, M, N)
    return P


def decrypt(P, S, F=256):
    """

    Args:
        P: 要解密的矩阵
        S: 密钥
        F: pixel值

    Returns: 解密后的数据

    """
    return dec.decryptioner(P, S, F)


if __name__ == '__main__':
    root_path = pu.get_root_path()
    file_path = pu.path_join(root_path, pu.INPUT_PATH, '200px-Lenna.jpg')
    P = iu.read_img(file_path, iu.READ_GRAY)
    encrypted_img = encrypt(P, SECRET_KEY, 256).astype(np.uint8)
    iu.print_img(encrypted_img, "encrypted_lena")
    anti_encrypted_img = dec.decryptioner(encrypted_img, SECRET_KEY,
                                          256).astype(np.uint8)
    iu.print_img(anti_encrypted_img, "anti-encrypted_lena")
示例#8
0
        out = pu.path_join(root_path, pu.REC_PATH)
        pth = pu.path_join(out, name)
        iu.save_img(img, pth)

    @staticmethod
    def composition(img0, img1, img2, img3):
        a = np.hstack((img0, img1))
        b = np.hstack((img2, img3))
        all = np.vstack((a, b))
        return all


def __test(img, LM):
    e = Receiver(img, LM)
    e.decryption()
    e.data_extraction(104)
    e.recomposition()
    Receiver.save(e.res_img, 'res.png')


if __name__ == '__main__':
    root_path = pu.get_root_path()
    file1_name = "image.png"
    file1_path = pu.path_join(root_path, pu.OUTPUT_PATH, file1_name)
    file2_name = "LM.png"
    file2_path = pu.path_join(root_path, pu.OUTPUT_PATH, file2_name)

    encrypted_img = iu.read_img(file1_path, iu.READ_GRAY)
    LM = iu.read_img(file2_path, iu.READ_GRAY)
    __test(encrypted_img, LM)
示例#9
0
import src.util.image_util as iu
import src.util.path_util as pu

import numpy as np

if __name__ == '__main__':
    root_path = pu.get_root_path()
    src_black_img = iu.read_img(
        pu.path_join(root_path, pu.INPUT_PATH, "200px-Lenna.jpg"),
        iu.READ_GRAY)
    res_black_img = iu.read_img(
        pu.path_join(root_path, "static", "integral", "res.png"), iu.READ_GRAY)

    src_color_img = iu.read_img(
        pu.path_join(root_path, pu.INPUT_PATH, "trees.png"), iu.READ_COLOR)
    res_color_img = iu.read_img(
        pu.path_join(root_path, "static", "integral_rgba", "res.png"),
        iu.READ_COLOR)

    diff_color_img = abs(
        src_color_img.astype(np.int) - res_color_img.astype(np.int)).astype(
            np.uint8)
    diff_black_img = abs(
        src_black_img.astype(np.int) - res_black_img.astype(np.int)).astype(
            np.uint8)

    iu.print_imgs(diff_black_img, diff_color_img)

    diff_color_path = pu.path_join(root_path, "static", "difference",
                                   "color_difference.png")
    diff_black_path = pu.path_join(root_path, "static", "difference",