Skip to content

Guide · Open source

How to use blind_watermark: embed and extract image watermarks in Python

Updated · written with AI from the project's own documentation and checked against our catalogue data

blind_watermark is an open-source Python library that hides a text or bit-array watermark inside an image, using a DWT-DCT-SVD method and a password. Its main feature is that the watermark can be extracted without the original image, which is what 'blind' refers to. This guide shows how to install it, embed and extract a watermark from Python and from the command line, and what the README says about attacks such as cropping and resizing.

blind-watermarkguofei9987/blind_watermark · ★ 14.8k · MIT

Quick start

  1. 1Install the package. Run pip install blind-watermark in a Python 3 environment.
  2. 2Choose passwords. Pick a password_img and password_wm. You must use the same values when extracting.
  3. 3Load the original image. Call read_img with the path to your picture.
  4. 4Set the watermark. Use read_wm with a string (mode='str'), a bit list (mode='bit'), or an image file path.
  5. 5Embed and save. Call embed with the output file path, such as output/embedded.png.
  6. 6Extract the watermark. Create a new WaterMark with the same passwords, then call extract with the file, wm_shape and the matching mode.

Install blind_watermark from PyPI

Install the package with pip from PyPI. The README lists Python 3 as the requirement (its badge indicates python>=3.5).

  • Requirement: Python 3 (README badge indicates python>=3.5)
  • The README also describes a developer version installed from a git clone, for those who want the latest source.
pip install blind-watermark

Embed and extract a watermark from the command line

The package ships a command-line tool named blind_watermark. Use --embed to write a watermark into an image, and --extract to read it back. The password given with --pwd must match for extraction. For extraction, the README notes that the watermark shape (--wm_shape) is needed.

  • --embed: takes the password, the source image, the watermark text and an output file
  • --extract: takes the same password, --wm_shape, and the watermarked image
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

Embed and extract a text watermark in Python

Create a WaterMark object with password_img and password_wm, read the original image with read_img, set the watermark with read_wm(mode='str'), then call embed. The README's example also records the watermark bit length, which is needed for extraction.

To extract, create a new WaterMark object with the same passwords and call extract with the output file, the watermark length as wm_shape, and mode='str'. The README shows the extracted text as the output.

  • Use the same password_img and password_wm for embedding and extraction
  • Keep the length of the watermark bits (len(bwm1.wm_bit)) so you can pass it as wm_shape
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) 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 an image as the watermark

You can also use a picture as the watermark. Read the watermark with read_wm and a file path, then embed. For extraction, the README uses a tuple shape for the watermark and an out_wm_name to save the recovered image.

  • The README example uses a 128 by 128 watermark shape when extracting an image watermark
  • out_wm_name sets the file where the extracted watermark image is saved
from blind_watermark import WaterMark bwm1 = WaterMark(password_wm=1, password_img=1) bwm1.read_img('pic/ori_img.jpg') bwm1.read_wm('pic/watermark.png') bwm1.embed('output/embedded.png') bwm1 = WaterMark(password_wm=1, password_img=1) bwm1.extract(filename='output/embedded.png', wm_shape=(128, 128), out_wm_name='output/extracted.png', )

Use a bit array as the watermark

For data that is not text, pass a list of booleans with mode='bit'. Set wm_shape when you create the WaterMark object for extraction. The extracted output is an array of floats, so the README advises applying a threshold such as 0.5 to turn it into bits.

  • Embed: read_wm([True, False, True, True, True, False], mode='bit')
  • Extract: pass wm_shape=6 and mode='bit' to extract, then threshold the floats at 0.5
bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6) wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit') print(wm_extract)

Check how the watermark holds up to edits

The README includes a table of attacks on a watermarked image and shows that the extracted watermark was recovered for each one. The listed attacks are rotation by 45 degrees, random crop, masks, vertical and horizontal cuts, resize, pepper noise and brightness reduced by 10%. Use these as a guide to test your own images. The README does not give numeric benchmarks, so test with your own pictures before relying on the result.

  • Attacks listed in the README: rotate 45 degrees, random crop, masks, vertical cut, horizontal cut, resize, pepper noise, brightness down 10%
  • Run the same extraction on your own edited copies to see if your mark survives

What people use it for

  • Adding a hidden ownership or tracing mark to images from a Python script
  • Testing whether a watermark survives cropping, resizing, rotation or brightness changes
  • Studying frequency-domain (DWT-DCT-SVD) watermarking in a readable Python codebase
  • Embedding a short bit array or text string into a picture for later extraction

Frequently asked questions

Is blind_watermark free to use?

The project is released under the MIT licence, as shown in the README and PyPI badge. Check the LICENSE file in the repository for the full terms before using it in a commercial product.

How do I install blind_watermark?

Run pip install blind-watermark. The README lists Python 3 as the prerequisite. A developer version can be installed from a git clone followed by pip install.

Do I need the original image to extract the watermark?

No. The README states that extraction does not require the original image, which is the meaning of 'blind' in the name. You do need the same passwords and the watermark shape.

What does wm_shape mean and why is it needed?

wm_shape is the shape or length of the watermark you embedded. The README says it is necessary for extraction, and for text you can use the length of the watermark bits.

Can blind_watermark work on video or audio?

No. The README covers images only. For text, the related project text_blind_watermark is listed in the README.

Is blind_watermark good enough for legal proof of ownership?

Not on its own. The README shows robustness against listed attacks and does not make security or legal claims, so it should not be your only proof of ownership.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Use blind_watermark if you are a Python developer who wants to hide an ownership or tracing mark in images, or to test how a mark survives common edits. Pick something else if you need a guaranteed tamper-proof mark, a point-and-click app, or support for video or audio.

Install options & downloads