# -*- coding: utf-8 -*- # run origin.py to generate the embedded image from blind_watermark import att # 亮度调高攻击 att.bright_att('output/embedded.png', 'output/亮度调高攻击.png', ratio=1.1) #%% 提取水印 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')
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) att.bright_att(input_filename='output/亮度攻击.png', output_file_name='output/亮度攻击_还原.png', ratio=1.1) wm_extract = bwm1.extract('output/亮度攻击_还原.png', wm_shape=len_wm, mode='str') print("亮度攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致'
from blind_watermark import att #%% 亮度调低攻击 att.bright_att('output/打上水印的图.png', 'output/亮度调低攻击.png', ratio=0.9) #%% 提取水印 from blind_watermark import WaterMark bwm1 = WaterMark(4399, 2333, 36, 20, wm_shape=(128, 128)) bwm1.extract('output/亮度调低攻击.png', 'output/亮度调低攻击_提取水印.png')
# -*- coding: utf-8 -*- # run origin.py to generate the embedded image from blind_watermark import att # %% 亮度调低攻击 att.bright_att('output/embedded.png', 'output/亮度调低攻击.png', ratio=0.9) # %% 提取水印 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')
# %%遮挡攻击 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='str') print(f"遮挡攻击{n}次后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %%缩放攻击 att.resize_att('output/embedded.png', 'output/缩放攻击.png', out_shape=(400, 300)) 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='str') print("缩放攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %% att.bright_att('output/embedded.png', 'output/亮度攻击.png', ratio=0.9) att.bright_att('output/亮度攻击.png', 'output/亮度攻击_还原.png', ratio=1.1) wm_extract = bwm1.extract('output/亮度攻击_还原.png', wm_shape=len_wm, mode='str') print("亮度攻击后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致'
from blind_watermark import att # 亮度调高攻击 att.bright_att('output/打上水印的图.png', 'output/亮度调高攻击.png', ratio=1.1) #%% 提取水印 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')
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) assert np.all(wm == wm_extract), '提取水印和原水印不一致'