In this issue, we recommend a Python tool for adding and extracting blind watermarks from images—Blind Watermark.
blind_watermark is a Python tool that can add and extract blind watermarks from images, and supports four ways: adding numbers, embedding images, embedding text, and embedding binaries. It can prevent effects such as rotation angle, random screenshots, multiple occlusion, vertical cropping, horizontal cropping, zoom attacks, etc.
Installation
pip install blind-watermark
Or install the latest development version
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
use
command line
# Embed Watermark:
blind_watermark –embed –pwd 1234 examples/pic/ori_img.jpeg “watermark text” examples/output/embedded.png
# Extract Watermark:
blind_watermark –extract –pwd 1234 –wm_shape 111 examples/output/embedded.png
Python
- Embed text watermarks
from blind_watermark import WaterMarkbwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img(‘pic/ori_img.jpg’)
wm = ‘@guofei9987 Long live open source! ‘
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 text watermarks
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract(‘output/embedded.png’, wm_shape=len_wm, mode=’str’)
print(wm_extract)
Embed image watermarks
from blind_watermark import WaterMarkbwm1 = 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 image watermarks
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’, )
Effects of various attacks
blind_watermark is a Python tool that can add and extract blind watermarks from images, and supports four ways: adding numbers, embedding images, embedding text, and embedding binaries. It can prevent effects such as rotation angle, random screenshots, multiple occlusion, vertical cropping, horizontal cropping, zoom attacks, etc.
Installation
pip install blind-watermark
Or install the latest development version
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
use
command line
# Embed Watermark:
blind_watermark –embed –pwd 1234 examples/pic/ori_img.jpeg “watermark text” examples/output/embedded.png
# Extract Watermark:
blind_watermark –extract –pwd 1234 –wm_shape 111 examples/output/embedded.png
Python
Embed text watermarks
from blind_watermark import WaterMark
bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img(‘pic/ori_img.jpg’)
wm = ‘@guofei9987 Long live open source! ‘
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 text watermarks
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract(‘output/embedded.png’, wm_shape=len_wm, mode=’str’)
print(wm_extract)
Embed image watermarks
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 image watermarks
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’, )
Effects of various attacks
This project uses the MIT open source license, and you can read more about it by yourself.