# guofei9987/blind_watermark architecture

> Architecture diagram of the GitHub repository guofei9987/blind_watermark, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guofei9987/blind_watermark
- Repository: https://github.com/guofei9987/blind_watermark

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces
    subgraph "User Interfaces"
        CLI["CLI Entrypoint\n(console script)"]:::frontend
        API["Python API\n(WaterMark class)"]:::frontend
    end

    %% Core Package
    subgraph "Core Package"
        WM["WaterMark class\n(coordination)"]:::core
        CORE["bwm_core\n(algorithm engine)"]:::core
        VER["version.py\n(metadata"]:::core
        REQS_CORE["requirements.txt\n(core)"]:::core
    end

    %% Utilities
    subgraph "Utilities"
        ATT["att\n(attack simulations)"]:::util
        POOL["pool\n(concurrency)"]:::util
        RECOVER["recover\n(recovery helpers)"]:::util
    end

    %% Data I/O
    subgraph "Data I/O"
        IMGIO["Image I/O\n(Pillow/OpenCV)"]:::io
        FORMATS["Watermark formats\n(text, image, bit array)"]:::io
        IOSTORE["Filesystem\n(read/write images)"]:::io
    end

    %% External Dependencies
    subgraph "External Dependencies"
        NP["NumPy"]:::infra
        SCIPY["SciPy"]:::infra
        PIL["Pillow/OpenCV"]:::infra
        MP["multiprocessing"]:::infra
    end

    %% Supporting Systems
    subgraph "Supporting Systems"
        EXAMPLES["examples"]:::infra
        DOCS["docs"]:::infra
        CI_GH[".github/workflows"]:::infra
        CI_TRAVIS[".travis.yml"]:::infra
        FUNDING[".github/FUNDING.yml"]:::infra
        SETUP["setup.py"]:::infra
        REQS_TOP["requirements.txt"]:::infra
    end

    %% Connections
    CLI -->|calls| WM
    API -->|calls| WM

    WM -->|reads images| IMGIO
    WM -->|reads watermark| FORMATS
    IMGIO --> PIL

    WM -->|embed/extract| CORE
    CORE -->|returns array| WM

    CORE -->|simulate attack| ATT
    ATT -->|attacked array| CORE

    WM -->|parallel tasks| POOL
    POOL -->|workers execute| CORE

    WM -->|coeff recovery| RECOVER

    WM -->|write file| IOSTORE
    IOSTORE -->|feeds for extract| WM

    CORE --> NP
    CORE --> SCIPY
    WM --> MP
    POOL --> MP

    %% Packaging & CI
    SETUP -->|publishes| REQS_TOP
    SETUP -->|includes| REQS_CORE
    CI_GH -->|runs tests| WM
    CI_TRAVIS -->|runs tests| WM
    FUNDING -->|metadata| WM
    DOCS -->|docs site| WM
    EXAMPLES -->|sample usage| WM

    %% Click Events
    click CLI "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/cli_tools.py"
    click API "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/blind_watermark.py"
    click CORE "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/bwm_core.py"
    click ATT "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/att.py"
    click RECOVER "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/recover.py"
    click POOL "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/pool.py"
    click VER "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/version.py"
    click REQS_CORE "https://github.com/guofei9987/blind_watermark/blob/master/blind_watermark/requirements.txt"
    click SETUP "https://github.com/guofei9987/blind_watermark/blob/master/setup.py"
    click REQS_TOP "https://github.com/guofei9987/blind_watermark/blob/master/requirements.txt"
    click DOCS "https://github.com/guofei9987/blind_watermark/tree/master/docs/"
    click EXAMPLES "https://github.com/guofei9987/blind_watermark/tree/master/examples/"
    click CI_GH "https://github.com/guofei9987/blind_watermark/blob/master/.github/workflows/tests.yml"
    click CI_TRAVIS "https://github.com/guofei9987/blind_watermark/blob/master/.travis.yml"
    click FUNDING "https://github.com/guofei9987/blind_watermark/blob/master/.github/FUNDING.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef core fill:#d4edda,stroke:#155724,color:#155724;
    classDef util fill:#fff3cd,stroke:#856404,color:#856404;
    classDef io fill:#f0f0f0,stroke:#6c757d,color:#6c757d;
    classDef infra fill:#e2e3e5,stroke:#818182,color:#818182;
```
