文章目录
一、关于 blind-watermark
Blind watermark 基于 DWT-DCT-SVD.
- github : https://github.com/guofei9987/blind_watermark
- Documentation: https://blindwatermark.github.io/blind_watermark/#/en/
- 文档: https://blindwatermark.github.io/blind_watermark/#/zh/
- Source code: https://github.com/guofei9987/blind_watermark
- Discussions : https://github.com/guofei9987/blind_watermark/discussions
安装
shell
pip install blind-watermark
源码安装当前开发版本
shell
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
二、bash 中使用
shell
# 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
See the codes
嵌入水印:
python
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))
提取水印:
python
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
3、embed images
嵌入水印:
python
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')
提取水印:
python
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 method | image after attack | extracted watermark |
---|---|---|
Rotate 45 Degrees | [ | |
Random crop | ||
Mask |
4、embed array of bits
See it here
作为 demo,我们嵌入 6 bytes 数据:
python
wm = [True, False, True, True, True, False]
嵌入:
python
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')
提取:
python
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
- text_blind_watermark (将消息嵌入文本): https://github.com/guofei9987/text_blind_watermark
- HideInfo(隐藏为图像、隐藏为声音、隐藏为文本):https://github.com/guofei9987/HideInfo