Remove Watermark
Remove watermarks from white-background document images. Pure local processing, no API key needed.
When to Use
Trigger this skill when the user wants to:
- - Remove watermarks from document images or screenshots
- Clean up exam paper screenshots for printing
- Remove light text overlays (e.g., "公众号·xxx", website names)
Workflow: 4-Step Process
The script path is scripts/remove_watermark.py relative to this SKILL.md.
Use uv run --with Pillow --with numpy (add --with scipy only when using --region full).
Step 1: Visual Analysis (Claude reads the image)
Use the Read tool to look at a sample image. Identify:
- - Is there a watermark? If no, skip processing.
- Where is it? (bottom-right corner, center, scattered across the image)
- What type? (light gray text, dark logo/stamp, colored)
- Does it overlap with content text?
Estimate the watermark region as approximate percentages: y0%, y1%, x0%, x1%.
Step 2: Brightness Analysis (script analyzes the region)
Run the analyze subcommand on the watermark region to determine the right threshold:
CODEBLOCK0
Example: INLINECODE5
This prints brightness distribution and a suggested threshold.
Step 3: Remove Watermark
Use the suggested threshold and region from Steps 1-2:
CODEBLOCK1
Region presets: bottom-right, bottom-left, top-right, top-left, bottom, top, right, left, center, INLINECODE15
Custom region: --region "y0,y1,x0,x1" as percentages (e.g., "94,100,60,100" = bottom 6%, right 40%)
Step 4: Verify and Auto-Retry
Use the Read tool to check the output image. You MUST verify and retry if needed — do not stop after one attempt.
Check these two things:
- 1. Is the watermark gone?
- Is the text content intact (not lightened or damaged)?
If watermark is still visible, retry with adjusted parameters:
| Problem | Fix |
|---|
| Watermark still visible | Lower the threshold (e.g., 180 → 130 → 80) |
| Only partially removed |
Expand the region (e.g., widen by 5-10% in each direction) |
| Text got damaged/lightened | Raise the threshold or shrink the region to avoid text areas |
| Wrong area processed | Re-examine the image and correct the region coordinates |
Retry rules:
- - Retry up to 3 times with different parameters before giving up
- Each retry: adjust ONE parameter at a time (threshold OR region, not both)
- If the suggested threshold from
analyze didn't work, try halving it - If threshold=50 still doesn't remove the watermark, try threshold=1 with a tighter region (the region likely has no real content, so blanking it entirely is safe)
- After 3 failed attempts, report to the user what was tried and ask for guidance
Command Reference
analyze
CODEBLOCK2
Prints brightness distribution and suggested threshold for a region.
remove
CODEBLOCK3
| Flag | Default | Description |
|---|
| INLINECODE19 | INLINECODE20 | Region to process (preset name or y0,y1,x0,x1) |
| INLINECODE22 |
180 | Brightness cutoff for watermark pixels |
|
--enhance | off | Boost text contrast after removal |
|
--preview | off | Print stats without saving |
Tips
- - Region mode is always preferred over full mode when watermark is localized. It leaves all text perfectly intact.
- For dark watermarks (logo, stamps), use a low threshold (80-120) with a tight region.
- For light gray text watermarks, use a higher threshold (160-200).
- Same batch: if all images in a folder have the same watermark position, analyze one image and apply the same settings to all.
- Combine with image-to-pdf skill: remove watermarks first, then combine into PDF.
去除水印
从白色背景的文档图片中去除水印。纯本地处理,无需API密钥。
使用场景
当用户想要以下操作时,触发此技能:
- - 从文档图片或截图中去除水印
- 清理试卷截图以便打印
- 去除浅色文字叠加层(例如:公众号·xxx、网站名称)
工作流程:4步处理
脚本路径为相对于此SKILL.md文件的scripts/remove_watermark.py。
使用uv run --with Pillow --with numpy(仅在--region full模式下添加--with scipy)。
第1步:视觉分析(Claude读取图片)
使用读取工具查看示例图片。识别以下内容:
- - 是否存在水印? 如果没有,跳过处理。
- 水印位置?(右下角、中心、分散在图片各处)
- 水印类型?(浅灰色文字、深色徽标/印章、彩色)
- 是否与内容文字重叠?
将水印区域估算为近似百分比:y0%、y1%、x0%、x1%。
第2步:亮度分析(脚本分析区域)
在水印区域运行analyze子命令,确定合适的阈值:
bash
uv run --with Pillow --with numpy python3 /scripts/remove_watermark.py analyze <图片> --region y0,y1,x0,x1
示例:analyze sample.jpg --region 94,100,60,100
这将输出亮度分布和建议阈值。
第3步:去除水印
使用第1-2步得到的建议阈值和区域:
bash
区域模式(推荐 - 对区域外的文字零损伤)
uv run --with Pillow --with numpy python3
/scripts/remove_watermark.py remove <输入> -o <输出> --region y0,y1,x0,x1 --threshold
全图模式(水印分散在各处时使用 - 需要scipy)
uv run --with Pillow --with numpy --with scipy python3 /scripts/remove_watermark.py remove <输入> -o <输出> --threshold
区域预设: bottom-right、bottom-left、top-right、top-left、bottom、top、right、left、center、full
自定义区域: --region y0,y1,x0,x1 以百分比形式(例如:94,100,60,100 = 底部6%,右侧40%)
第4步:验证和自动重试
使用读取工具检查输出图片。必须验证并在需要时重试——不要在一次尝试后就停止。
检查以下两点:
- 1. 水印是否已去除?
- 文字内容是否完好无损(未变淡或受损)?
如果水印仍然可见,使用调整后的参数重试:
| 问题 | 解决方法 |
|---|
| 水印仍然可见 | 降低阈值(例如:180 → 130 → 80) |
| 仅部分去除 |
扩大区域(例如:每个方向扩大5-10%) |
| 文字受损/变淡 | 提高阈值或缩小区域以避开文字区域 |
| 处理了错误区域 | 重新检查图片并修正区域坐标 |
重试规则:
- - 在放弃前最多重试3次,使用不同参数
- 每次重试:一次只调整一个参数(阈值或区域,不同时调整)
- 如果analyze给出的建议阈值无效,尝试将其减半
- 如果阈值=50仍无法去除水印,尝试使用更精确的区域和阈值=1(该区域可能没有真实内容,完全清空是安全的)
- 经过3次失败尝试后,向用户报告已尝试的方法并寻求指导
命令参考
analyze
remove_watermark.py analyze <图片> [--region REGION]
输出指定区域的亮度分布和建议阈值。
remove
remove_watermark.py remove <输入...> [-o 输出] [--region REGION] [--threshold N] [--enhance]
| 参数 | 默认值 | 描述 |
|---|
| --region | full | 要处理的区域(预设名称或y0,y1,x0,x1) |
| --threshold |
180 | 水印像素的亮度阈值 |
| --enhance | 关闭 | 去除后增强文字对比度 |
| --preview | 关闭 | 仅输出统计信息,不保存 |
提示
- - 区域模式始终优于全图模式,当水印位于局部区域时。它能完美保留所有文字。
- 对于深色水印(徽标、印章),使用低阈值(80-120)配合精确区域。
- 对于浅灰色文字水印,使用较高阈值(160-200)。
- 批量处理:如果文件夹中所有图片的水印位置相同,分析一张图片后将相同设置应用于所有图片。
- 结合图片转PDF技能:先去除水印,再合并为PDF。