Frequency-domain watermarking library and CLI
Project description
FDWM - Frequency Domain Watermarking
A Python library for embedding and extracting watermarks in images using frequency domain techniques. Supports both image and text watermarks with a command-line interface.
Features
- Frequency Domain Watermarking: Uses FFT (Fast Fourier Transform) to embed watermarks in high-frequency regions
- Grid-based Embedding: Embeds watermark in multiple grid cells for robust extraction
- Image Watermarks: Embed and extract image-based watermarks
- Text Watermarks: Embed and extract text watermarks with OCR support
- Command Line Interface: Easy-to-use CLI for batch processing
- Multiple Languages: Support for various text languages
- Robust Extraction: High correlation coefficients for reliable watermark detection
Installation
From PyPI (Recommended)
pip install fdwm
From Source
git clone https://github.com/Liam0205/fdwm.git
cd fdwm
pip install -e .
Quick Start
Python API
import cv2
from fdwm import embed, extract, extract_text
# Load host image and watermark
host_img = cv2.imread('host.jpg')
watermark_img = cv2.imread('watermark.png')
# Embed watermark using grid strategy (3x3 grid by default)
out_path, metrics = embed(host_img, watermark_img, strength=0.1)
print("Watermarked image saved to:", out_path)
print("Metrics:", metrics)
# Extract watermark
extracted_watermark = extract(out_path, watermark_img.shape[:2])
# For text watermarks
text = "Hello World"
out_path, metrics = embed(host_img, None, 'watermarked.png', watermark_text=text, strength=0.1)
extracted_text = extract_text(out_path)
Note:
embedreturns a tuple(output_path, metrics).metricsis a dict with keys:'mean_pixel_diff','max_pixel_diff','p90_pixel_diff','psnr'.
Command Line Interface
# Embed image watermark (3x3 grid by default)
fdwm embed host.jpg --watermark-img watermark.png
# Embed with custom grid size
fdwm embed host.jpg --watermark-img watermark.png --grid-m 4 --grid-n 4
# Embed text watermark
fdwm embed host.jpg --watermark-text "Hello World"
# Extract image watermark
fdwm extract watermarked.jpg
# Extract text watermark
fdwm extract watermarked.jpg --text
Embedding Method
FDWM uses a grid-based embedding strategy:
- Grid Division: The image is divided into
m × ngrid cells (default: 3×3) - Cell Processing: Each grid cell is processed independently in the frequency domain
- Corner Embedding: Within each cell, the watermark is embedded in the top-left corner
- Fusion: During extraction, all grid cells are processed and averaged for robust recovery
This approach provides excellent robustness against cropping, rotation, and other geometric attacks.
CLI Usage
Embed Command
fdwm embed <host_image> [options]
Options:
--watermark-img PATH Watermark image path
--watermark-text TEXT Watermark text
--strength FLOAT Embedding strength (default: 30000.0)
--scale FLOAT Watermark scale relative to host (default: 0.25)
--font PATH Font file path for text watermark
--font-size INT Font size for text watermark
--grid-m INT Number of vertical grid divisions (default: 3)
--grid-n INT Number of horizontal grid divisions (default: 3)
--debug Print detailed metrics for each processed image
Extract Command
fdwm extract <watermarked_image> [options]
Options:
--strength FLOAT Embedding strength used during embedding (default: 30000.0)
--scale FLOAT Watermark scale relative to host (default: 0.25)
--output PATH Directory to save extracted watermark images/text
--text Perform OCR and output text instead of image
--save-text Save recognized text to .txt files
--grid-m INT Number of vertical grid divisions used during embedding (default: 3)
--grid-n INT Number of horizontal grid divisions used during embedding (default: 3)
Examples
Basic Usage
# Embed watermark with default 3x3 grid
fdwm embed image.jpg --watermark-text "Secret"
# Embed with 4x4 grid for higher robustness
fdwm embed image.jpg --watermark-text "Secret" --grid-m 4 --grid-n 4
# Extract text
fdwm extract watermarked.jpg --text
Batch Processing
# Embed watermark in all images in a directory
fdwm embed images/ --watermark-img watermark.png
# Extract watermark from all images
fdwm extract watermarked/ --output extracted/
Text Watermarking
# Embed Chinese text
fdwm embed image.jpg --watermark-text "Hello World"
# Extract text
fdwm extract watermarked.jpg --text
Requirements
- Python 3.10+
- numpy
- opencv-python
- Pillow
- pytesseract
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Based on frequency domain watermarking techniques
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fdwm-0.2.2.tar.gz.
File metadata
- Download URL: fdwm-0.2.2.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc468e72b2dd280c48aa8fedb30276152d11afd59ea11c60b5db7cb45795f38b
|
|
| MD5 |
594ae51a8ae8da2bfa5847eb2a61edaf
|
|
| BLAKE2b-256 |
54c0ce8d76b177dba32edfb2b22c82686b6b2aa1a61f57a823c0bbbf3de8324a
|
Provenance
The following attestation bundles were made for fdwm-0.2.2.tar.gz:
Publisher:
workflow.yml on Liam0205/fdwm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fdwm-0.2.2.tar.gz -
Subject digest:
fc468e72b2dd280c48aa8fedb30276152d11afd59ea11c60b5db7cb45795f38b - Sigstore transparency entry: 254488932
- Sigstore integration time:
-
Permalink:
Liam0205/fdwm@9f5f6a784f74ddb49c99223db0dcba7ae74b3393 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/Liam0205
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@9f5f6a784f74ddb49c99223db0dcba7ae74b3393 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fdwm-0.2.2-py3-none-any.whl.
File metadata
- Download URL: fdwm-0.2.2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d02efc91d799353c11ed77408752f795d721b6e235da9637eda429b7fe6dbb11
|
|
| MD5 |
1f8eeff6a4ac759b1984d8e7639f3817
|
|
| BLAKE2b-256 |
1958cd518c2e2a7af86621a4060ab7693a1cfe49ac6c4480c558a2e2dbbc0dbf
|
Provenance
The following attestation bundles were made for fdwm-0.2.2-py3-none-any.whl:
Publisher:
workflow.yml on Liam0205/fdwm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fdwm-0.2.2-py3-none-any.whl -
Subject digest:
d02efc91d799353c11ed77408752f795d721b6e235da9637eda429b7fe6dbb11 - Sigstore transparency entry: 254488933
- Sigstore integration time:
-
Permalink:
Liam0205/fdwm@9f5f6a784f74ddb49c99223db0dcba7ae74b3393 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/Liam0205
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@9f5f6a784f74ddb49c99223db0dcba7ae74b3393 -
Trigger Event:
release
-
Statement type: