Blind Watermark in Python
Project description
blind-watermark
Blind watermark based on dct and svd.
- Documentation: https://BlindWatermark.github.io/blind_watermark/#/en/
- 文档: https://BlindWatermark.github.io/blind_watermark/#/zh/
- 中文 readme README_cn.md
- Source code: https://github.com/guofei9987/blind_watermark
install
pip install blind-watermark
For the current developer version:
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
How to use
Use in 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
Use in Python
Original Image + Watermark = Watermarked Image
+ '@guofei9987 开源万岁!' =
See the codes
Embed watermark:
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))
Extract watermark:
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 开源万岁!
attacks on Watermarked Image
attack method | image after attack | extracted watermark |
---|---|---|
Rotate 45 Degrees | '@guofei9987 开源万岁!' | |
Random crop | '@guofei9987 开源万岁!' | |
Masks | '@guofei9987 开源万岁!' | |
50% Horizontal cut | '@guofei9987 开源万岁!' | |
50% Vertical cut | '@guofei9987 开源万岁!' | |
Resize 0.5 | '@guofei9987 开源万岁!' | |
Pepper Noise | '@guofei9987 开源万岁!' | |
Brightness 10% Down | '@guofei9987 开源万岁!' |
embed images
embed watermark:
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')
Extract watermark:
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 |
embed array of bits
See it here
As demo, we embed 6 bytes data:
wm = [True, False, True, True, True, False]
Embed:
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')
Extract:
bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6)
wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit')
print(wm_extract)
Notice that wm_shape
(shape of watermark) is necessary
The output wm_extract
is an array of float. set a threshold such as 0.5.
Concurrency
WaterMark(..., processes=None)
processes
: number of processes, can be integer. DefaultNone
, meaning use all processes.
Related Project
text_blind_watermark: https://github.com/guofei9987/text_blind_watermark
Embed message into text.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file blind_watermark-0.4.4.tar.gz
.
File metadata
- Download URL: blind_watermark-0.4.4.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04c976a7a8d2031a754048e1181a75410b66b98a9941468365bee4aa733a996e |
|
MD5 | 071e7aa1ce6e253fb245df3890380d7e |
|
BLAKE2b-256 | 112a1f209958d9ddf83cb4895132c9329224b96093945e8d3ce331e2064966e0 |
File details
Details for the file blind_watermark-0.4.4-py3-none-any.whl
.
File metadata
- Download URL: blind_watermark-0.4.4-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb7a9587b3c682f4fc8a8f8a0b728668931bca18e580a7de70e134088764aede |
|
MD5 | b635c51df7278894970b4534e400fd6d |
|
BLAKE2b-256 | 490e566fcbff9284c058c048207b46aed3645adeb4d6fb1e514fa4ad2653930f |