blind_watermark README

The project's README from github.com/guofei9987/blind_watermark. As one markdown file: README.md.

blind-watermark

Blind watermark based on DWT-DCT-SVD.

PyPI Build Status codecov License Python Platform stars fork Downloads Discussions Featured|HelloGitHub

install

pip install blind-watermark

For the current developer version:

git clone [email protected]: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

origin_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 开源万岁!'
Vertical cut 横向裁剪攻击 '@guofei9987 开源万岁!'
Horizontal cut 纵向裁剪攻击 '@guofei9987 开源万岁!'
Resize 缩放攻击 '@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)

blind_watermark (guofei9987/blind_watermark)

Searching Database…

What is this?This is a Python library for blind, invisible image watermarking: you embed a hidden watermark into an image and can later extract it without needing the original, un-watermarked image.
Is this a library or a command-line tool?It is a Python library that can also be driven straight from the command line, so you can either import it in Python code or run bash commands to embed and extract watermarks.
How do I get it embedding watermarks?Install the package for your Python environment, then call the embed function on an image plus your watermark data, and the matching extract function to pull it back out later.
Do I need anything besides Python?No extra dependencies are called out in the README beyond Python itself; you can optionally pass a processes argument to use multiprocessing for faster embedding.
Does the watermark survive edits to the image?The demos show the hidden watermark surviving 45-degree rotation, random cropping, masking, vertical/horizontal cuts, resizing, pepper noise, and a 10% brightness drop, but robustness naturally depends on how severe the distortion is.
What kinds of data can I embed as a watermark?You can embed a text string, another image, or a raw array of bits as the watermark payload.
Why doesn't extraction need the original image?The library is a 'blind' watermarking method by design, meaning the watermark can be pulled directly out of the watermarked image without comparing it to the original.
Are there related projects for watermarking other media?The same author maintains 'textblindwatermark' for hiding messages inside text and 'HideInfo' for hiding data as images, sounds, or text.
Creator
guofei9987
Size
3.9 MB
Stars
14.8K
Age
7y
Commits · 90 Days