remove-ai-watermarks

repository·main·Indexed 26 days ago

https://github.com/wiltodelta/remove-ai-watermarks

A tool to strip visible and invisible AI watermarks and provenance metadata from images. It supports removing visible labels such as Gemini (Nano Banana) sparkles, Doubao, Jimeng, and Samsung Galaxy AI marks, as well as invisible pixel watermarks via diffusion regeneration and metadata including C2PA, EXIF, and XMP.

Tokens
28.1K
Snippets
34
Records
192
Agent score
89%

What's inside remove-ai-watermarks

  1. Understand the SynthID-Image mechanism

    main

    SynthID-Image is a post-hoc, model-independent watermarking system. Unlike in-generation watermarks that inject signals into a model's latent noise, SynthID-Image is applied to the raw pixel output after the generative model (e.g., Imagen or Gemini) has finished its work.

    Key architectural characteristics:

    • Pixel-space embedding: The watermark is stamped onto pixels using a separate neural network encoder f, not within the model's latent activations.
    • Model independence: The generative model does not need to be modified to support watermarking, and replacing the model does not remove the watermarking capability.
    • Deep learning based: It uses jointly-trained deep learning models (encoder and decoder) rather than classical frequency-domain methods like DWT-DCT. This allows the signal to be optimized for imperceptibility and robustness against specific perturbations.
  2. Understand C2PA 2.4 'Durable Content Credentials'

    main

    C2PA 2.4 introduces 'soft bindings' (invisible watermarks or content fingerprints) that link an asset to a server-side manifest repository.

    Implication for developers: While remove_ai_metadata successfully deletes the embedded manifest from the file, the asset may still be re-linked to its provenance via these soft bindings in a remote repository. Stripping the file is a necessary but potentially insufficient step for complete provenance removal against C2.4 standards.

  3. Understand the package architecture and processing paths

    main

    The package provides four primary processing paths for handling input files:

    1. Identify provenance: Generates a ProvenanceReport by identifying metadata and watermarks.
    2. Visible mark removal: Produces a localized and filled image by removing visible watermarks.
    3. Invisible regeneration: Uses diffusion to regenerate the image and remove invisible watermarks.
    4. Metadata stripping: Removes AI-related metadata from the container.

    The all command executes these in order: visible removal, optional invisible regeneration, and metadata stripping.

  4. Commercial usage restrictions for PhotoMaker-V2 and face restoration extras

    main

    The photomaker extra (implemented in photomaker_restore.py) and other face-restoration features are NON-COMMERCIAL.

    While the adapter weights may be Apache-2.0, the PhotoMaker-V2 pipeline uses a dual ID encoder that requires InsightFace (antelopev2/buffalo_l model packs) to generate ArcFace embeddings. These model packs are released under a non-commercial/research-only license.

    To ensure a monetized deployment remains legal, do NOT install or use the photomaker extra.

  5. Determine required img2img strength for SynthID removal

    main

    Empirical testing shows that the required img2img strength to remove SynthID watermarks varies significantly by vendor. When testing removal, use the following benchmarks as a guide:

    VendorOracleRequired img2img strength
    OpenAIopenai.com/verify0.05
    GoogleGemini "Verify with SynthID"0.15

    Key Findings:

    • Vendor Dominance: Google's SynthID is roughly 3x more robust than OpenAI's.
    • Resolution Independence: For OpenAI, removal strength is consistent across resolutions (e.g., 1024x1536 to 1600x1600 all clear at 0.05).
    • Google Resolution Note: For Google, testing was performed on capped resolutions (--max-resolution 1536). Native large Gemini images (e.g., 2816x1536) may require higher strength (>= 0.30) or discrete GPU resources.
  6. Identify commercial-safe face identity mechanisms

    main

    When building a pipeline that requires identity preservation without re-introducing SynthID watermarks, you must use semantic embeddings (conditioning a fresh generation) rather than pixel-based restoration (like GFPGAN or CodeFormer), as pixel-based methods can transport the watermark.

    Commercial-Safe Path

    • PhotoMaker-V1: Uses OpenCLIP-ViT-H/14 (MIT license) for identity encoding. It does not use the InsightFace/ArcFace branch, making it end-to-end commercial-safe (Apache-2.0 adapter + MIT encoder).

    Non-Commercial Paths (Avoid for paid services)

    Any stack requiring insightface.app.FaceAnalysis to compute ArcFace embeddings is blocked for commercial use due to the InsightFace model-pack license. This includes:

    • PhotoMaker-V2
    • IP-Adapter FaceID
    • InstantID
    • PuLID
    • Arc2Face
  7. Prototype text restoration methods

    main

    When building a pipeline to restore text after a global scrub, two primary research-grade approaches are recommended:

    • TextSR: Uses a detector, multilingual OCR, and character-shape diffusion priors. This is the closest approach to existing detector-driven pipelines.
    • EasyText: Uses FLUX-DiT glyph re-rendering. It supports multilingual text (including CJK) and utilizes the 16-channel VAE.

    Implementation Requirements:

    • Requires a new OCR-recognition step (the current system only detects text; it does not recognize the content needed for re-rendering).
    • Requires heavy FLUX/DiT-class models, typically necessitating serverless GPU infrastructure.
    • Verification: Because restoration is diffusion-based, you must empirically verify that the restored output contains no watermarks by running the SynthID oracle on the final output.
  8. Install invisible watermark removal support

    main

    Diffusion-based invisible watermark removal requires the gpu extra. The code supports CUDA, XPU, MPS, and CPU devices, though a GPU is recommended for performance.

    To install with GPU support using uv:

    uv tool install --force "remove-ai-watermarks[gpu]"

    For the CUDA-only Qwen Image plus Z-Image profile (which includes standard gpu dependencies):

    uv tool install --force "remove-ai-watermarks[qwen-zimage]"
    uv tool install --force "remove-ai-watermarks[gpu]"
  9. Prototype an SDXL-native ControlNet removal pipeline

    main

    To test if structure-conditioned regeneration can remove watermarks while preserving text, prototype an SDXL-native ControlNet pipeline instead of using the SD1.5 ctrlregen profile. The goal is to find a 'Pareto cell' where the watermark is removed (verified via the Gemini SynthID oracle) and text remains legible.

    Prototype Configuration

    • Base Model: SDXL base 1.0
    • ControlNet Models: Use xinsir/controlnet-canny-sdxl-1.0 or xinsir/controlnet-tile-sdxl-1.0 (avoid the Union model for API robustness).
    • Resolution: Run at full resolution (1024px or higher), NOT 512px tiles.
    • VAE: Use madebyollin/sdxl-vae-fp16-fix.
    • Precision: Use fp32 activations (especially on MPS/Apple Silicon to avoid all-black NaN issues).

    Sweep Parameters

    Perform a sweep across the following dimensions:

    • Denoise strength: {0.15, 0.3, 0.5, 0.7, 1.0}
    • controlnet_conditioning_scale: {0.5, 0.8, 1.0}
    • Control type: {tile, canny}

    Verification

    1. Removal: Manually verify using the Gemini app "Verify with SynthID" oracle (or openai.com/verify for gpt-images).
    2. Text: Use OCR round-trip or visual inspection for legibility of small text.
    3. Fidelity: Measure SSIM/FID against the original.
    uv run python scripts/controlnet_sweep.py watermarked.png -o sweep_out
  10. Handle unsupported or missed visible watermarks

    main
    Automatic detection is calibrated for specific vendor/locale templates (e.g., Samsung Italian variants) and may miss redesigned, unsupported locale, or cropped marks. If you can see a mark that the tool fails to detect automatically, use the --region flag to manually specify the area for erasure.
  11. Capture Doubao visible watermarks for detection calibration

    main

    To calibrate the detection silhouette used by src/remove_ai_watermarks/doubao_engine.py, you must capture the '豆包AI生成' visible watermark over known flat backgrounds. This process provides the necessary inputs for scripts/visible_alpha_solve.py doubao to rebuild the detection mask.

    Capture Procedure (Image-Edit Path)

    1. Generate Seed: Use a solid-color seed image.
    2. Upload to Doubao: Use doubao.com specifically. Open Doubao image generation, use the image-edit / reference mode, and upload your seed.
    3. Prompt: Use the following prompt (Chinese preferred) to ensure the watermark is the only variable: 请完全按照原图重新生成这张图片,保持完全一致,不要添加或修改任何内容 (English: Recreate this image exactly as it is, keep it identical, do not add or change anything)
    4. Download: Download the ORIGINAL output file.
      • DO NOT take a screenshot.
      • DO NOT crop, edit, or re-save the image.
      • DO NOT use Jimeng / Dreamina (they use different marks).

    Capture Requirements

    To ensure high-quality calibration, capture images following these priorities:

    Aspect RatioBlack CapturesWhite CapturesGray128 CapturesPurpose
    1:1311Primary alpha map & blend mode verification
    16:9211Landscape anchor rule
    9:16211Portrait anchor rule
    4:3 or 3:41 each--Optional anchor refinement

    Note on Resolutions: If the UI offers multiple resolutions (1K, 2K, 4K), capture one black image per resolution on 1:1 to calibrate how the watermark scales.

    Hygiene & Best Practices

    • Format: PNG is preferred. If Doubao only provides JPEG, note this.
    • Fallback: If edit mode is unavailable, generate 10-12 normal-content images at a fixed resolution and extract the watermark using per-pixel min/median analysis.
    • Validation: Capture 3-5 normal-content images on 1:1 for end-to-end removal validation.
  12. Identify watermarks in Gemini API and AI Studio images

    main

    Images generated via the Gemini API, AI Studio, or Nano Banana do not contain C2PA or IPTC metadata. They only contain the SynthID pixel watermark and a visible sparkle.

    To successfully identify these images using the identify method, you must enable visible sparkle detection by setting check_visible=True. Otherwise, the tool will return Unknown because the metadata is missing.