关于对于旋转攻击鲁棒性的疑问
Author: asdcaszcCreated Mar 11, 2025Updated Dec 11, 2025
代码库是基于DWT-DCT-SVD创建的,我测试了本代码的鲁棒性,嵌入和提取水印代码如下所示。使用的attacks是基于kornia进行的。
from blind_watermark import WaterMark
bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('cat.png')
bwm1.read_wm([True, False, True, True, True, False], mode='bit')
bwm1.embed('cat-w.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))import blind_watermark
from blind_watermark import WaterMark
import PIL
import utils_img_k
import torchvision
import matplotlib.pyplot as plt
import torch.nn.functional as F
import torch
blind_watermark.bw_notes.close()
device = 'cuda' if torch.cuda.is_available() else 'cpu'
attacks = {
'none': lambda x: x,
# 'crop_01': lambda x: utils_img_k.center_crop(x, 0.1),
# 'crop_09': lambda x: utils_img_k.center_crop(x, 0.9),
# 'resize_03': lambda x: utils_img_k.resize(x, 0.3),
# 'resize_05': lambda x: utils_img_k.resize(x, 0.5),
'rot_45': lambda x: utils_img_k.rotate(x, 45),
# 'rot_180': lambda x: utils_img_k.rotate(x, 180),
# 'blur': lambda x: utils_img_k.gaussian_blur(x, sigma=4.0, kernel_size=3),
# 'brightness_3': lambda x: utils_img_k.adjust_brightness(x, 3),
# 'jpeg_30': lambda x: utils_img_k.jpeg_compress(x, 30),
# 'gaussian_noise': lambda x: utils_img_k.gaussian_noise(x, std=0.1),
}
for name, attack in attacks.items():
print(name)
# distortion
file_path = f"cat-w.png"
image_w = PIL.Image.open(file_path).convert('RGB')
to_tensor = torchvision.transforms.ToTensor()
image_w = to_tensor(image_w).unsqueeze(0).to(torch.float32).to(device)
image_w_distortion = attack(image_w)
if image_w_distortion.shape != image_w.shape:
image_w_distortion = F.interpolate(image_w_distortion, size=512, mode='bilinear')
to_pil = torchvision.transforms.ToPILImage()
pil_image = to_pil(image_w_distortion.squeeze(0))
# 显示图片
plt.imshow(pil_image)
plt.axis("off") # 关闭坐标轴
plt.show()
temp_path = f"cat-d.png"
pil_image.save(temp_path)
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('cat-d.png', mode='bit',wm_shape=6)
print(wm_extract)我所使用的未嵌入图片如下所示,由AI随机生成。
部分受攻击图像如图所示
提取水印的结果如下所示,对于图像旋转和剪切其实鲁棒性并不像作者声称的那么好。作者使用的剪切是Mask,而brightness可能是干扰强度过大的问题。
none
[ True False True True True False]
crop_01
[ True True True False False False]
crop_09
[ True True False False False True]
resize_03
[ True False True True True False]
resize_05
[ True False True True True False]
rot_45
[ True False False False True True]
rot_180
[ True True True False False True]
blur
[ True False True True True False]
brightness_3
[False True False False False True]
jpeg_30
[ True False True True True False]
gaussian_noise
[ True False True True True False]而且基于其他论文和代码库中中的表现,例如 Zodiac 代码: Zodiac Invisible Watermark
他们对于旋转的鲁棒性也并不佳。其他攻击下的鲁棒性确实是不错的。
Source: guofei9987/blind_watermark