The Problem
Watermarks are everywhere on the internet. While they serve a legitimate purpose for copyright protection, there are valid use cases for removing them — like cleaning up your own photos or processing stock images you’ve licensed.
I wanted to build an automated tool that could:
- Detect watermarks in images
- Segment the watermark region precisely
- Inpaint the area with realistic content
The Architecture
After experimenting with different approaches, I settled on a three-stage pipeline:
Input Image → [YOLO Detection] → [Florence-2 Segmentation] → [LaMa Inpainting] → Clean Image
Stage 1: Detection with YOLO
I fine-tuned a YOLOv8 model on a custom dataset of watermarked images. The model excels at detecting watermark bounding boxes with high confidence scores.
from ultralytics import YOLO
model = YOLO("watermark_yolov8.pt")
results = model(image)
boxes = results[0].boxes
Stage 2: Segmentation with Florence-2
Once we have bounding boxes, Florence-2 provides pixel-level segmentation of the watermark region. This is crucial for clean inpainting — a rough bounding box would leave artifacts.
Stage 3: Inpainting with LaMa
LaMa (Large Mask Inpainting) is state-of-the-art for filling in masked regions. It handles complex textures and structures remarkably well.
Results
The pipeline achieves:
- 95%+ detection accuracy on common watermark types
- Clean inpainting with minimal visible artifacts
- Batch processing support for handling large image sets
Lessons Learned
- Data quality matters more than model complexity — spending time on a good dataset for YOLO training paid off more than trying fancier architectures
- Pipeline design is key — each model does one thing well, and the composition produces great results
- Edge cases are hard — semi-transparent watermarks and watermarks over complex backgrounds remain challenging
What’s Next
- Support for video watermark removal (frame-by-frame processing)
- Web interface for easy access
- API endpoint for integration into other tools
If you’re interested in the technical details, check out the GitHub repo.