# %%遮挡攻击 n = 60 att.shelter_att(input_filename='output/embedded.png', output_file_name='output/多遮挡攻击.png', ratio=0.1, n=n) # 提取 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/多遮挡攻击.png', wm_shape=len_wm, mode='str') print(f"遮挡攻击{n}次后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %%缩放攻击 att.resize_att(input_filename='output/embedded.png', output_file_name='output/缩放攻击.png', out_shape=(400, 300)) att.resize_att(input_filename='output/缩放攻击.png', output_file_name='output/缩放攻击_还原.png', out_shape=ori_img_shape[::-1]) # out_shape 是分辨率,需要颠倒一下 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/缩放攻击_还原.png', wm_shape=len_wm, mode='str') print("缩放攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %% att.bright_att(input_filename='output/embedded.png', output_file_name='output/亮度攻击.png', ratio=0.9)
# -*- coding: utf-8 -*- # run origin.py to generate the embedded image from blind_watermark import att # 缩放攻击 att.resize_att('output/embedded.png', 'output/缩放攻击.png', out_shape=(800, 600)) att.resize_att('output/缩放攻击.png', 'output/缩放攻击_还原.png', out_shape=(1920, 1200)) # out_shape 是分辨率,需要颠倒一下 # %%提取水印 from blind_watermark import WaterMark bwm1 = WaterMark(password_wm=1, password_img=1) bwm1.extract(filename="output/缩放攻击_还原.png", wm_shape=(128, 128), out_wm_name="output/缩放攻击_提取水印.png")
from blind_watermark import att # 缩放攻击 att.resize_att('output/打上水印的图.png', 'output/缩放攻击.png', out_shape=(800, 600)) att.resize_att('output/缩放攻击.png', 'output/缩放攻击_还原.png', out_shape=(1920, 1200)) # out_shape 是分辨率,需要颠倒一下 # %%提取水印 from blind_watermark import WaterMark bwm1 = WaterMark(4399, 2333, 36, 20, wm_shape=(128, 128)) bwm1.extract("output/缩放攻击_还原.png", "output/缩放攻击_提取水印.png")
att.rot_att('output/embedded.png', 'output/旋转攻击.png', angle=45) att.rot_att('output/旋转攻击.png', 'output/旋转攻击_还原.png', angle=-45) # 提取水印 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/旋转攻击_还原.png', wm_shape=len_wm, mode='bit') print("旋转攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%遮挡攻击 n = 60 att.shelter_att('output/embedded.png', 'output/多遮挡攻击.png', ratio=0.1, n=n) # 提取 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/多遮挡攻击.png', wm_shape=len_wm, mode='bit') print(f"遮挡攻击{n}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%缩放攻击 att.resize_att('output/embedded.png', 'output/缩放攻击.png', out_shape=(800, 600)) att.resize_att('output/缩放攻击.png', 'output/缩放攻击_还原.png', out_shape=ori_img_shape[::-1]) # out_shape 是分辨率,需要颠倒一下 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/缩放攻击_还原.png', wm_shape=len_wm, mode='bit') print("缩放攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致'
wm_extract = bwm1.extract(embed_img=img_recovered, wm_shape=len_wm, mode='str') print(f"旋转攻击angle={angle}后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %%遮挡攻击 n = 60 img_attacked = att.shelter_att(input_img=embed_img, ratio=0.1, n=n) # 提取 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract(embed_img=img_attacked, wm_shape=len_wm, mode='str') print(f"遮挡攻击{n}次后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %%缩放攻击 img_attacked = att.resize_att(input_img=embed_img, out_shape=(400, 300)) img_recovered = att.resize_att(input_img=img_attacked, out_shape=ori_img_shape[::-1]) # out_shape 是分辨率,需要颠倒一下 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract(embed_img=img_recovered, wm_shape=len_wm, mode='str') print("缩放攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %% img_attacked = att.bright_att(input_img=embed_img, ratio=0.9) img_recovered = att.bright_att(input_img=img_attacked, ratio=1.1) wm_extract = bwm1.extract(embed_img=img_recovered, wm_shape=len_wm, mode='str') print("亮度攻击后的提取结果:", wm_extract)