Skip to main content

Frequency-domain watermarking library and CLI

Project description

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
  • Flexible Region Selection: Choose from corners, center, or random regions for watermark embedding
  • 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 in corners (default)
watermarked_img = embed(host_img, watermark_img, strength=0.1, region_type="corners")

# Embed watermark in center region
watermarked_img = embed(host_img, watermark_img, strength=0.1, region_type="center")

# Embed watermark in random regions with seed
watermarked_img = embed(host_img, watermark_img, strength=0.1, region_type="random", random_seed=42)

# Extract watermark (use same region_type as embedding)
extracted_watermark = extract(watermarked_img, watermark_img.shape[:2], region_type="corners")

# For text watermarks
text = "Hello World"
watermarked_img = embed(host_img, text, strength=0.1, is_text=True, region_type="center")
extracted_text = extract_text(watermarked_img, region_type="center")

Command Line Interface

# Embed image watermark in corners (default)
fdwm embed host.jpg --watermark-img watermark.png

# Embed image watermark in center region
fdwm embed host.jpg --watermark-img watermark.png --region-type center

# Embed image watermark in random regions
fdwm embed host.jpg --watermark-img watermark.png --region-type random --random-seed 42

# Embed text watermark
fdwm embed host.jpg --watermark-text "Hello World" --region-type center

# Extract image watermark (use same region_type as embedding)
fdwm extract watermarked.jpg --region-type center

# Extract text watermark
fdwm extract watermarked.jpg --text --region-type center

Region Types

FDWM supports three different region types for watermark embedding:

1. Corners (Default)

Embeds watermark in the four corners of the image:

  • Top-left corner: Main region with full strength
  • Bottom-right corner: Flipped watermark with 50% strength
  • Top-right corner: Horizontally flipped with 50% strength
  • Bottom-left corner: Vertically flipped with 50% strength

This provides good robustness against cropping attacks.

2. Center

Embeds watermark in the center region of the image (30% of image size).

  • Provides good resistance to edge cropping
  • Maintains watermark integrity in central areas

3. Random

Embeds watermark in random regions using a specified seed:

  • Uses 5 random positions by default
  • Applies random transformations (flips)
  • Requires random_seed parameter for reproducible results
  • Provides high security through obfuscation

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
  --region-type TYPE      Region type: corners, center, random (default: corners)
  --random-seed INT       Random seed for reproducible random embedding

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
  --region-type TYPE      Region type used during embedding: corners, center, random (default: corners)
  --random-seed INT       Random seed used during embedding

Examples

Different Region Types

# Embed in corners (most robust)
fdwm embed image.jpg --watermark-text "Secret" --region-type corners

# Embed in center (resistant to edge cropping)
fdwm embed image.jpg --watermark-text "Secret" --region-type center

# Embed in random regions (high security)
fdwm embed image.jpg --watermark-text "Secret" --region-type random --random-seed 12345

# Extract using same region type
fdwm extract watermarked.jpg --text --region-type center

Batch Processing

# Embed watermark in all images in a directory
fdwm embed images/ --watermark-img watermark.png --region-type center

# Extract watermark from all images
fdwm extract watermarked/ --region-type center --output extracted/

Text Watermarking

# Embed Chinese text in center region
fdwm embed image.jpg --watermark-text "Hello World" --region-type center

# Extract text
fdwm extract watermarked.jpg --text --region-type center

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
  • Uses OpenCV for image processing
  • Tesseract OCR for text extraction

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fdwm-0.2.1.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fdwm-0.2.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file fdwm-0.2.1.tar.gz.

File metadata

  • Download URL: fdwm-0.2.1.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fdwm-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fcdb34bd669919f2ea0f33fd1abeb8b51365f37c61304bebfdc152d1d9e654b2
MD5 4167ff89f91823e7e039fab574cb97e2
BLAKE2b-256 0d265ac8be9170152431583da4050b1495f6ad98e63339520ca13b9a81c13ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fdwm-0.2.1.tar.gz:

Publisher: workflow.yml on Liam0205/fdwm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fdwm-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fdwm-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fdwm-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79b2617f16532cc6c5602cc3792eed40bfa2d70ece33772958af4a1325af76c7
MD5 f91ce51f07693ade66889b06aa138085
BLAKE2b-256 698e2960388cccbeec13b0dd5ddb5d109317c068f0f6c13513f12cb844a0cc91

See more details on using hashes here.

Provenance

The following attestation bundles were made for fdwm-0.2.1-py3-none-any.whl:

Publisher: workflow.yml on Liam0205/fdwm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page