How guofei9987/blind_watermark works
Project type and purpose
• Type: a Python library + CLI for embedding and extracting blind watermarks in images using DWT–DCT–SVD.
• Purpose: provide both a command‑line interface and a Python API to hide/extract text, bit arrays or images robustly, with optional attack simulations and multiprocessing.
File structure
• Top‑level:
– blind_watermark/ (the core package)
– docs/ (documentation source and static site)
– examples/ (sample scripts and notebooks)
– setup.py, requirements.txt (packaging)
– CI configs: .github/, .travis.yml
• Inside blind_watermark/:
– cli_tools.py – parses CLI arguments & dispatches commands
– blind_watermark.py – defines the WaterMark class, high‑level embed/extract API
– bwm_core.py – the DWT–DCT–SVD embed/extract algorithm implementation
– att.py – routines to simulate image attacks (rotate, crop, noise…)
– pool.py – concurrency support (multiprocessing)
– recover.py – helper for reconstructing the watermark
– version.py / requirements.txt
README for additional insights
• Describes two usage modes: CLI (blind_watermark --embed/--extract) and Python import (from blind_watermark import WaterMark).
• Highlights attack robustness, concurrency, and supported watermark formats (text, image, bit array).
• Shows dependencies (Python ≥3.5, NumPy, Pillow/OpenCV, etc.), CI badges, and docs URL.
Main components and interactions
A. User Interfaces
1. CLI Entrypoint (console script “blind_watermark”) –> cli_tools
2. Python API –> blind_watermark.WaterMark
B. Core Package
1. WaterMark class (coordination)
2. bwm_core (DWT–DCT–SVD embed/extract pipeline)
3. att (attack simulations, optional)
4. recover (watermark recovery helpers)
5. pool (manages parallel processing)
C. Data I/O
– Image I/O (Pillow/OpenCV)
– Watermark formats: text→bit‑array, PIL image, list of booleans
– Filesystem (read/write images)
D. External Dependencies
– NumPy, SciPy, Pillow/OpenCV, multiprocessing
E. Supporting Systems
– Examples folder (integration points)
– Documentation site (docs/ via MkDocs or custom generator)
– CI pipelines (.github workflows, Travis)
– Packaging (setup.py → PyPI)
• CLI or Python API → calls WaterMark.read_img & read_wm → passes arrays to bwm_core → bwm_core returns modified array → WaterMark.embed writes file.
• For extraction: image file → WaterMark.extract → flows through recover & bwm_core → returns string/array or image.
• Optional: att module can sit between embed and extract to simulate attacks.
Architectural patterns & design principles
• Modular separation: CLI/parser layer (cli_tools) vs. core logic (bwm_core, recover) vs. utilities (att, pool).
• Strategy pattern: multiple modes (str, bit, image) handled by WaterMark via pluggable readers.
• Pipeline pattern: sequential transforms DWT → DCT → SVD → inverse.
• Concurrency: pool module abstracts multiprocessing.