Gemini Watermark Remover
Remove the visible Gemini AI watermark (star/sparkle logo) from generated images using mathematically accurate reverse alpha blending.
Fully offline — pure Python, no external binary downloads, no network access.
When to Use
- - Remove the Gemini watermark from AI-generated images
- Batch process a directory of Gemini-generated images
- Clean images before publishing or sharing
- Automate watermark removal in pipelines
Quick Start
Install Dependencies (one-time)
CODEBLOCK0
Requires: Python ≥ 3.9. No Rust toolchain, no compiled binaries, no downloads.
Basic Usage
CODEBLOCK1
How It Works
Gemini adds a semi-transparent white star/sparkle logo to generated images using alpha blending:
CODEBLOCK2
This tool reverses the equation to recover the original pixels:
CODEBLOCK3
The alpha map (watermark transparency pattern) is generated mathematically as a
4-pointed star (central Gaussian core + 4 elongated cardinal rays) at two sizes:
- - 48×48 with 32 px margin — images where either dimension ≤ 1024 px
- 96×96 with 64 px margin — images where both dimensions > 1024 px
For improved accuracy you can supply your own alpha map derived from a background
capture of the Gemini watermark on a white background (--alpha-map).
Detection
Before removal, a three-stage algorithm checks whether a watermark is present:
- 1. Spatial NCC (50% weight) — normalised cross-correlation with the alpha map
- Gradient NCC (30% weight) — edge signature matching via Sobel operators
- Variance Analysis (20% weight) — texture dampening detection
Images without detected watermarks are automatically skipped.
CLI Parameters
| Parameter | Short | Default | Description |
|---|
| INLINECODE1 | | (required) | Input image file or directory |
| INLINECODE2 |
-o |
{name}_cleaned.{ext} | Output file or directory |
|
--force |
-f |
false | Skip detection, process unconditionally |
|
--threshold |
-t |
0.35 | Detection confidence threshold (0.0–1.0) |
|
--force-small | |
false | Force 48×48 watermark size |
|
--force-large | |
false | Force 96×96 watermark size |
|
--alpha-map | | (built-in) | Custom grayscale alpha map image |
|
--verbose |
-v |
false | Enable detailed output |
|
--quiet |
-q |
false | Suppress all non-error output |
Supported Formats
| Format | Read | Write |
|---|
| JPEG (.jpg, .jpeg) | Yes | Yes (quality 100) |
| PNG (.png) |
Yes | Yes |
| WebP (.webp) | Yes | Yes |
| BMP (.bmp) | Yes | Yes |
Usage Examples
CODEBLOCK4
Deriving a Custom Alpha Map
For pixel-perfect removal, capture the Gemini watermark on a pure white
background and compute:
CODEBLOCK5
Save the result as a grayscale PNG and pass it via --alpha-map.
Output
- - Single file — saves to
-o path, or {name}_cleaned.{ext} by default - Directory — saves all processed images to the output directory
- Skipped images — images without detected watermarks are not modified (unless
--force) - Exit code — 0 on success, 1 if any image fails
Troubleshooting
"No watermark detected" on a watermarked image
- - Try lowering the threshold: INLINECODE26
- Or bypass detection entirely: INLINECODE27
- Consider supplying a custom alpha map for your watermark variant
Image looks distorted after removal
- - The image may not have a Gemini watermark. Use detection (avoid
--force) - Try
--force-small or --force-large to match the correct size - Supply a custom alpha map for better precision
"Image too small" warning
The image dimensions are smaller than the watermark region. This typically
means the image does not have a Gemini watermark.
ModuleNotFoundError: Pillow or numpy
CODEBLOCK6
Limitations
- - Visible watermark only — this tool removes the visible star/sparkle logo watermark
- Cannot remove SynthID — Google's invisible watermark (SynthID) is embedded at the pixel level during generation and cannot be reversed
- Fixed position only — handles watermarks in the standard bottom-right position only
- Built-in alpha map is approximate — use
--alpha-map with a captured reference for exact results
Gemini 水印去除工具
使用数学精确的反向Alpha混合技术,从生成的图像中移除可见的Gemini AI水印(星形/闪光标志)。
完全离线运行 — 纯Python实现,无需外部二进制文件下载,无需网络访问。
适用场景
- - 从AI生成的图像中移除Gemini水印
- 批量处理包含Gemini生成图像的目录
- 在发布或分享前清理图像
- 在流程中自动化水印移除
快速开始
安装依赖(一次性操作)
bash
pip install Pillow numpy
推荐:使用uv进行更快速、隔离的安装
uv pip install Pillow numpy
要求:Python ≥ 3.9。无需Rust工具链、无需编译二进制文件、无需下载。
基本用法
bash
单张图像(自动检测水印,保存为photo_cleaned.jpg)
python3 scripts/remove_watermark.py photo.jpg
指定输出路径
python3 scripts/remove
watermark.py photo.jpg -o cleanphoto.jpg
批量处理目录
python3 scripts/remove
watermark.py ./inputdir -o ./output_dir
强制移除,跳过检测
python3 scripts/remove_watermark.py photo.jpg -o clean.jpg --force
工作原理
Gemini通过Alpha混合在生成的图像上添加半透明白色星形/闪光标志水印:
带水印图像 = alpha 255 + (1 - alpha) 原始图像
本工具通过反向计算还原原始像素:
原始图像 = (带水印图像 - alpha * 255) / (1 - alpha)
Alpha图(水印透明度图案)通过数学方式生成为4角星形(中心高斯核心 + 4个拉长的轴向射线),有两种尺寸:
- - 48×48,带32像素边距 — 任一维度 ≤ 1024 像素的图像
- 96×96,带64像素边距 — 两个维度均 > 1024 像素的图像
为提高精度,您可以提供从白色背景上捕获的Gemini水印背景图像中提取的自定义Alpha图(--alpha-map)。
检测机制
在移除前,通过三阶段算法检查水印是否存在:
- 1. 空间NCC(50%权重)— 与Alpha图的归一化互相关
- 梯度NCC(30%权重)— 通过Sobel算子进行边缘特征匹配
- 方差分析(20%权重)— 纹理衰减检测
未检测到水印的图像将自动跳过。
CLI参数
| 参数 | 缩写 | 默认值 | 描述 |
|---|
| input | | (必填) | 输入图像文件或目录 |
| --output |
-o | {名称}_cleaned.{扩展名} | 输出文件或目录 |
| --force | -f | false | 跳过检测,无条件处理 |
| --threshold | -t | 0.35 | 检测置信度阈值(0.0–1.0) |
| --force-small | | false | 强制使用48×48水印尺寸 |
| --force-large | | false | 强制使用96×96水印尺寸 |
| --alpha-map | | (内置) | 自定义灰度Alpha图图像 |
| --verbose | -v | false | 启用详细输出 |
| --quiet | -q | false | 抑制所有非错误输出 |
支持的格式
| 格式 | 读取 | 写入 |
|---|
| JPEG (.jpg, .jpeg) | 是 | 是(质量100) |
| PNG (.png) |
是 | 是 |
| WebP (.webp) | 是 | 是 |
| BMP (.bmp) | 是 | 是 |
使用示例
bash
详细输出(显示检测置信度、水印坐标)
python3 scripts/remove_watermark.py photo.png -o clean.png -v
降低检测阈值(更敏感)
python3 scripts/remove_watermark.py photo.jpg -t 0.15
强制使用大尺寸水印,忽略图像尺寸
python3 scripts/remove_watermark.py photo.jpg --force-large -o clean.jpg
批量处理,静默模式
python3 scripts/remove
watermark.py ./geminiimages/ -o ./cleaned/ -q
提供自定义Alpha图以获得更高精度
python3 scripts/remove
watermark.py photo.jpg --alpha-map myalpha.png
获取自定义Alpha图
要实现像素级精确移除,在纯白色背景上捕获Gemini水印并计算:
alpha(x, y) = max(R, G, B) / 255
将结果保存为灰度PNG,通过--alpha-map传入。
输出
- - 单个文件 — 保存到-o路径,默认保存为{名称}_cleaned.{扩展名}
- 目录 — 将所有处理后的图像保存到输出目录
- 跳过的图像 — 未检测到水印的图像不会被修改(除非使用--force)
- 退出码 — 成功返回0,任何图像处理失败返回1
故障排除
水印图像显示未检测到水印
- - 尝试降低阈值:-t 0.1
- 或完全绕过检测:--force
- 考虑为您的特定水印变体提供自定义Alpha图
移除后图像变形
- - 图像可能没有Gemini水印。请使用检测功能(避免使用--force)
- 尝试--force-small或--force-large以匹配正确尺寸
- 提供自定义Alpha图以获得更好精度
图像太小警告
图像尺寸小于水印区域。这通常意味着图像没有Gemini水印。
ModuleNotFoundError: Pillow 或 numpy
bash
pip install Pillow numpy
或
uv pip install Pillow numpy
局限性
- - 仅限可见水印 — 本工具仅移除可见的星形/闪光标志水印
- 无法移除SynthID — Google的隐形水印(SynthID)在生成过程中嵌入像素级别,无法逆向还原
- 仅限固定位置 — 仅处理标准右下角位置的水印
- 内置Alpha图为近似值 — 如需精确结果,请使用--alpha-map配合捕获的参考图像