Пример #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-dd",
                        "--data-dir",
                        type=str,
                        default=os.environ.get("KAGGLE_2020_ALASKA2"))

    args = parser.parse_args()
    data_dir = args.data_dir

    cover = fs.find_images_in_dir(os.path.join(data_dir, "Cover"))
    jimi = fs.find_images_in_dir(os.path.join(data_dir, "JMiPOD"))
    juni = fs.find_images_in_dir(os.path.join(data_dir, "JUNIWARD"))
    uerd = fs.find_images_in_dir(os.path.join(data_dir, "UERD"))

    for cover_fname, jimi_fname, juni_fname, uerd_fname in zip(
            tqdm(cover), jimi, juni, uerd):
        cover = decode_bgr_from_dct(fs.change_extension(cover_fname, ".npz"))
        jimi = decode_bgr_from_dct(fs.change_extension(jimi_fname, ".npz"))
        juni = decode_bgr_from_dct(fs.change_extension(juni_fname, ".npz"))
        uerd = decode_bgr_from_dct(fs.change_extension(uerd_fname, ".npz"))

        jimi_mask = block8_sum(np.abs(cover - jimi).sum(axis=2)) > 0
        juni_mask = block8_sum(np.abs(cover - juni).sum(axis=2)) > 0
        uerd_mask = block8_sum(np.abs(cover - uerd).sum(axis=2)) > 0

        cover_mask = jimi_mask | juni_mask | uerd_mask

        cv2.imwrite(fs.change_extension(cover_fname, ".png"), cover_mask * 255)
        cv2.imwrite(fs.change_extension(jimi_fname, ".png"), jimi_mask * 255)
        cv2.imwrite(fs.change_extension(juni_fname, ".png"), juni_mask * 255)
        cv2.imwrite(fs.change_extension(uerd_fname, ".png"), uerd_mask * 255)
Пример #2
0
def test_decoding_residual():
    # d:\datasets\ALASKA2\Cover\20805.jpg
    # d:\datasets\ALASKA2\UERD\20805.jpg

    # /home/bloodaxe/datasets/ALASKA2/Cover/18051.jpg
    # /home/bloodaxe/datasets/ALASKA2/UERD/18051.jpg

    # cover = cv2.imread("d:/datasets/ALASKA2/Cover/38330.jpg")
    # stego = cv2.imread("d:/datasets/ALASKA2/UERD/38330.jpg")

    # r1 = compute_decoding_residual(cover, "d:/datasets/ALASKA2/Cover/38330.npz")
    # r2 = compute_decoding_residual(stego, "d:/datasets/ALASKA2/UERD/38330.npz")

    cover = 255 * decode_bgr_from_dct(
        "d:/datasets/ALASKA2/Cover/50846.npz"
    )  # cv2.imread("d:/datasets/ALASKA2/Cover/50846.jpg")
    cover_cv2 = cv2.imread("d:/datasets/ALASKA2/Cover/50846.jpg")

    cv2.imwrite("cover_read_with_cv2.png", cover_cv2)
    cv2.imwrite("cover_from_dct.png", cover.astype(np.uint8))

    stego = 255 * decode_bgr_from_dct("d:/datasets/ALASKA2/JMiPOD/50846.npz")

    print(cover.max(), cover.min())
    cv2.imshow("Cover", cover.astype(np.uint8))
    cv2.imshow("Stego", stego.astype(np.uint8))
    cv2.waitKey(-1)
Пример #3
0
def test_dct_comp():

    methods = ["Cover", "JMiPOD", "JUNIWARD", "UERD"]

    cover_diff = None

    f, ax = plt.subplots(4, 4, figsize=(8 * 4, 8 * 4))
    for i, method in enumerate(methods):
        bgr = cv2.imread(os.path.join(TEST_DATA_DIR, method, "00001.jpg"))

        bgr_from_dct = decode_bgr_from_dct(
            os.path.join(TEST_DATA_DIR, method, "00001.npz"))
        bgr_from_dct_byte = (bgr_from_dct * 255).astype(np.uint8)

        if i == 0:
            cover_diff = cv2.absdiff(bgr_from_dct * 255,
                                     bgr.astype(np.float32)).sum(axis=2)

        decode_diff = cv2.absdiff(bgr_from_dct * 255,
                                  bgr.astype(np.float32)).sum(axis=2)
        print(decode_diff.mean(), decode_diff.std())
        ax[i, 0].imshow(bgr)
        ax[i, 0].axis("off")
        ax[i, 1].imshow(bgr_from_dct_byte)
        ax[i, 1].axis("off")
        ax[i, 2].imshow(decode_diff, cmap="gray")
        ax[i, 2].axis("off")
        ax[i, 3].imshow(cv2.absdiff(decode_diff, cover_diff), cmap="gray")
        ax[i, 3].axis("off")
    plt.show()
Пример #4
0
def compute_features_proc(image_fname):
    dct_file = fs.change_extension(image_fname, ".npz")
    image = 2 * (decode_bgr_from_dct(dct_file) / 140 - 0.5)

    entropy_per_channel = [
        entropy(image[..., 0].flatten()),
        entropy(image[..., 1].flatten()),
        entropy(image[..., 2].flatten()),
    ]

    f = [
        image[..., 0].mean(),
        image[..., 1].mean(),
        image[..., 2].mean(),
        image[..., 0].std(),
        image[..., 1].std(),
        image[..., 2].std(),
        entropy_per_channel[0],
        entropy_per_channel[1],
        entropy_per_channel[2],
    ]
    return f
Пример #5
0
def read_from_dct(image_fname):
    return decode_bgr_from_dct(fs.change_extension(image_fname, ".npz"))