17 Star 198 Fork 44

guofei9987 / blind_watermark

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

blind-watermark

基于频域的数字盲水印

PyPI Build Status codecov License Python Platform stars fork Downloads Discussions

安装

pip install blind-watermark

或者安装最新开发版本

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

如何使用

命令行中使用

# 嵌入水印:
blind_watermark --embed --pwd 1234 examples/pic/ori_img.jpeg "watermark text" examples/output/embedded.png
# 提取水印:
blind_watermark --extract --pwd 1234 --wm_shape 111 examples/output/embedded.png

Python 中使用

原图 + 水印 = 打上水印的图

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

参考 代码

嵌入水印

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)

Output:

@guofei9987 开源万岁!

各种攻击后的效果

攻击方式 攻击后的图片 提取的水印
旋转攻击45度 旋转攻击 '@guofei9987 开源万岁!'
随机截图 截屏攻击 '@guofei9987 开源万岁!'
多遮挡 多遮挡攻击 '@guofei9987 开源万岁!'
纵向裁剪 横向裁剪攻击 '@guofei9987 开源万岁!'
横向裁剪 纵向裁剪攻击 '@guofei9987 开源万岁!'
缩放攻击 缩放攻击 '@guofei9987 开源万岁!'
椒盐攻击 椒盐攻击 '@guofei9987 开源万岁!'
亮度攻击 亮度攻击 '@guofei9987 开源万岁!'

嵌入图片

参考 代码

嵌入:

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', )
攻击方式 攻击后的图片 提取的水印
旋转攻击45度 旋转攻击
随机截图 截屏攻击
多遮挡 多遮挡攻击 多遮挡_提取水印

隐水印还可以是二进制数据

参考 代码

作为 demo, 如果要嵌入是如下长度为6的二进制数据

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/打上水印的图.png')

解水印:(注意设定水印形状 wm_shape

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

解出的水印是一个0~1之间的实数,方便用户自行卡阈值。如果水印信息量远小于图片可容纳量,偏差极小。

并行计算

WaterMark(..., processes=None)
  • processes: 整数,指定线程数。默认为 None, 表示使用全部线程。

相关项目

MIT License Copyright (c) 2019 郭飞 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

图片盲水印,提取水印无须原图!开源隐水印 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/guofei9987/blind_watermark.git
git@gitee.com:guofei9987/blind_watermark.git
guofei9987
blind_watermark
blind_watermark
master

搜索帮助