# recover from attack: recover_crop(template_file='output/截屏攻击2.png', output_file_name='output/截屏攻击2_还原.png', loc=(x1, y1, x2, y2), image_o_shape=image_o_shape) bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/截屏攻击2_还原.png', wm_shape=len_wm, mode='str') print("截屏攻击,不知道攻击参数。提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %% Vertical cut r = 0.3 att.cut_att_width(input_filename='output/embedded.png', output_file_name='output/横向裁剪攻击.png', ratio=r) att.anti_cut_att(input_filename='output/横向裁剪攻击.png', output_file_name='output/横向裁剪攻击_填补.png', origin_shape=ori_img_shape) # 提取水印 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/横向裁剪攻击_填补.png', wm_shape=len_wm, mode='str') print(f"横向裁剪攻击r={r}后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %% horizontal cut r = 0.4 att.cut_att_height(input_filename='output/embedded.png',
from blind_watermark import att import numpy as np # 一次横向裁剪打击 att.cut_att_width('output/打上水印的图.png', 'output/横向裁剪攻击.png', ratio=0.5) att.anti_cut_att('output/横向裁剪攻击.png', 'output/横向裁剪攻击_填补.png', origin_shape=(1200, 1920)) # %%提取水印 from blind_watermark import WaterMark bwm1 = WaterMark(4399, 2333, 36, 20, wm_shape=(128, 128)) bwm1.extract("output/横向裁剪攻击_填补.png", "output/横向裁剪攻击_提取水印.png")
f'Crop attack\'s estimate parameters: x1={x1},y1={y1},x2={x2},y2={y2}. score={score}' ) # recover from attack: img_recovered = recover_crop(tem_img=img_attacked, loc=(x1, y1, x2, y2), image_o_shape=image_o_shape) bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract(embed_img=embed_img, wm_shape=len_wm, mode='str') print("截屏攻击,不知道攻击参数。提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %% Vertical cut r = 0.3 img_attacked = att.cut_att_width(input_img=embed_img, ratio=r) img_recovered = att.anti_cut_att(input_img=img_attacked, origin_shape=ori_img_shape) # 提取水印 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract(embed_img=img_recovered, wm_shape=len_wm, mode='str') print(f"横向裁剪攻击r={r}后的提取结果:", wm_extract) assert wm == wm_extract, '提取水印和原水印不一致' # %% horizontal cut r = 0.4 img_attacked = att.cut_att_height(input_img=embed_img, ratio=r) img_recovered = att.anti_cut_att(input_img=img_attacked, origin_shape=ori_img_shape)
# %%截屏攻击 loc = ((0.3, 0.1), (0.7, 0.9)) att.cut_att('output/embedded.png', 'output/截屏攻击.png', loc=loc) bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/截屏攻击.png', wm_shape=len_wm, mode='bit') print("截屏攻击{loc}后的提取结果:".format(loc=loc), wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %% # 一次横向裁剪打击 r = 0.2 att.cut_att_width('output/embedded.png', 'output/横向裁剪攻击.png', ratio=r) att.anti_cut_att('output/横向裁剪攻击.png', 'output/横向裁剪攻击_填补.png', origin_shape=ori_img_shape) # 提取水印 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract('output/横向裁剪攻击_填补.png', wm_shape=len_wm, mode='bit') print(f"横向裁剪攻击r={r}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%一次纵向裁剪攻击 ratio = 0.2 att.cut_att_height('output/embedded.png', 'output/纵向裁剪攻击.png', ratio=ratio) att.anti_cut_att('output/纵向裁剪攻击.png',
from blind_watermark import att import numpy as np # 一次横向裁剪打击 att.cut_att_width('output/打上水印的图.png', 'output/横向裁剪攻击.png') att.anti_cut_att('output/横向裁剪攻击.png', 'output/横向裁剪攻击_填补.png', origin_shape=(1200, 1920)) # %%提取水印 from blind_watermark import WaterMark bwm1 = WaterMark(4399, 2333, 36, 20, wm_shape=(128, 128)) bwm1.extract("output/横向裁剪攻击_填补.png", "output/横向裁剪攻击_提取水印.png")