一、关于 blind-watermark

Blind watermark 基于 DWT-DCT-SVD.


安装

pip install blind-watermark

源码安装当前开发版本

git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .


二、bash 中使用

# embed watermark into image:
blind_watermark --embed --pwd 1234 examples/pic/ori_img.jpeg "watermark text" examples/output/embedded.png

# extract watermark from image:
blind_watermark --extract --pwd 1234 --wm_shape 111 examples/output/embedded.png

三、Python 调用

1、基本使用

Original Image + Watermark = Watermarked Image

origin_image + ‘@guofei9987 开源万岁!’ = 打上水印的图


See the codes

嵌入水印:

from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('pic/ori_img.jpg')
wm = '@guofei9987 开源万岁!'
bwm1.read_wm(wm, mode='str')
bwm1.embed('output/embedded.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))

提取水印:

bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print(wm_extract)

输出:

@guofei9987 开源万岁!


2、attacks on Watermarked Image

attack methodimage after attackextracted watermark
Rotate 45 Degrees在这里插入图片描述‘@guofei9987 开源万岁!’
Random crop在这里插入图片描述‘@guofei9987 开源万岁!’
Masks在这里插入图片描述‘@guofei9987 开源万岁!’
Vertical cut横向裁剪攻击‘@guofei9987 开源万岁!’
Horizontal cut纵向裁剪攻击‘@guofei9987 开源万岁!’
Resize缩放攻击‘@guofei9987 开源万岁!’
Pepper Noise椒盐攻击‘@guofei9987 开源万岁!’
Brightness 10% Down亮度攻击‘@guofei9987 开源万岁!’

3、embed images

嵌入水印:

from blind_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# read original image
bwm1.read_img('pic/ori_img.jpg')
# read watermark
bwm1.read_wm('pic/watermark.png')
# embed
bwm1.embed('output/embedded.png')

提取水印:

bwm1 = WaterMark(password_wm=1, password_img=1)
# notice that wm_shape is necessary
bwm1.extract(filename='output/embedded.png', wm_shape=(128, 128), out_wm_name='output/extracted.png', )

attack methodimage after attackextracted watermark
Rotate 45 Degrees[旋转攻击在这里插入图片描述
Random crop在这里插入图片描述多遮挡_提取水印
Mask多遮挡攻击多遮挡_提取水印

4、embed array of bits

See it here

作为 demo,我们嵌入 6 bytes 数据:

wm = [True, False, True, True, True, False]

嵌入:

from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_ori_img('pic/ori_img.jpg')
bwm1.read_wm([True, False, True, True, True, False], mode='bit')
bwm1.embed('output/embedded.png')

提取:

bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6)
wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit')
print(wm_extract)

请注意,wm_shape(水印的形状)是必需的

输出 wm_extract 是一个浮点数组。设置阈值,例如0.5。


四、并发

WaterMark(..., processes=None)

  • processes 进程数可以是整数。默认为 None,这意味着使用所有进程。

五、相关 Project


点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部