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) # extract: 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, '提取水印和原水印不一致' # %%椒盐攻击 ratio = 0.05 att.salt_pepper_att(input_filename='output/embedded.png', output_file_name='output/椒盐攻击.png', ratio=ratio) # ratio是椒盐概率 # 提取 wm_extract = bwm1.extract('output/椒盐攻击.png', wm_shape=len_wm, mode='str') print(f"椒盐攻击ratio={ratio}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%旋转攻击 angle = 60 att.rot_att(input_filename='output/embedded.png', output_file_name='output/旋转攻击.png', angle=angle) att.rot_att(input_filename='output/旋转攻击.png', output_file_name='output/旋转攻击_还原.png',
# %%一次纵向裁剪攻击 ratio = 0.2 att.cut_att_height('output/embedded.png', 'output/纵向裁剪攻击.png', ratio=ratio) 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"纵向裁剪攻击ratio={ratio}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%椒盐攻击 ratio = 0.05 att.salt_pepper_att('output/embedded.png', 'output/椒盐攻击.png', ratio=ratio) # ratio是椒盐概率 # 提取 wm_extract = bwm1.extract('output/椒盐攻击.png', wm_shape=len_wm, mode='bit') print(f"椒盐攻击ratio={ratio}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%旋转攻击 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)
from blind_watermark import att import numpy as np import cv2 # %%椒盐攻击 att.salt_pepper_att('output/打上水印的图.png', 'output/椒盐攻击.png', ratio=0.05) # ratio是椒盐概率 # %%纵向裁剪打击.png 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')
# %% 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) # extract: 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, '提取水印和原水印不一致' # %%椒盐攻击 ratio = 0.05 img_attacked = att.salt_pepper_att(input_img=embed_img, ratio=ratio) # ratio是椒盐概率 # 提取 wm_extract = bwm1.extract(embed_img=img_attacked, wm_shape=len_wm, mode='str') print(f"椒盐攻击ratio={ratio}后的提取结果:", wm_extract) assert np.all(wm == wm_extract), '提取水印和原水印不一致' # %%旋转攻击 angle = 60 img_attacked = att.rot_att(input_img=embed_img, angle=angle) img_recovered = att.rot_att(input_img=img_attacked, angle=-angle) # 提取水印 bwm1 = WaterMark(password_wm=1, password_img=1) wm_extract = bwm1.extract(embed_img=img_recovered, wm_shape=len_wm, mode='str')