Skip to main content

FDWM - Frequency Domain Watermarking

PyPI version License: MIT

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

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:

  • embed returns a tuple (output_path, metrics).
  • metrics is 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:

  1. Grid Division: The image is divided into m × n grid cells (default: 3×3)
  2. Cell Processing: Each grid cell is processed independently in the frequency domain
  3. Corner Embedding: Within each cell, the watermark is embedded in the top-left corner
  4. 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

Metadata

Release files for fdwm 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fdwm 0.2.2
File Size Uploaded Provenance
fdwm-0.2.2.tar.gz 16.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fdwm 0.2.2
File Interpreter ABI Platform
fdwm-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / fdwm-0.2.2.tar.gz

Download URL fdwm-0.2.2.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fc468e72b2dd280c48aa8fedb30276152d11afd59ea11c60b5db7cb45795f38b
BLAKE2b-256 checksum
How to use checksums
54c0ce8d76b177dba32edfb2b22c82686b6b2aa1a61f57a823c0bbbf3de8324a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2025.

Transparency log

Release files / fdwm-0.2.2-py3-none-any.whl

Download URL fdwm-0.2.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d02efc91d799353c11ed77408752f795d721b6e235da9637eda429b7fe6dbb11
BLAKE2b-256 checksum
How to use checksums
1958cd518c2e2a7af86621a4060ab7693a1cfe49ac6c4480c558a2e2dbbc0dbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2025.

Transparency log

Security for fdwm 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fdwm-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page