fix: replace broken LaMa watermark detection with median filter approach

The luminance anomaly detection + LaMa inpainting approach failed because
watermark signal on the matted foreground was too weak (10-15 units vs
threshold of 25). Median filter with kernel=5 effectively removes
semi-transparent watermark text while preserving the stamp structure.

Pipeline is now: median filter (if toggle on) -> BiRefNet matting -> defringe.
No longer requires object-eraser-colorize bundle for watermark removal.
This commit is contained in:
SnapOtter
2026-05-13 17:08:15 +08:00
parent 132aa2cd0f
commit 443e9a4ffa
2 changed files with 17 additions and 180 deletions
@@ -2,7 +2,6 @@ import { ChevronDown, ChevronRight, Droplets } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { ProgressCard } from "@/components/common/progress-card";
import { useToolProcessor } from "@/hooks/use-tool-processor";
import { useFeaturesStore } from "@/stores/features-store";
import { useFileStore } from "@/stores/file-store";
type OutputFormat = "png" | "webp";
@@ -23,14 +22,6 @@ export function TransparencyFixerControls({
const [removeWatermark, setRemoveWatermark] = useState(false);
const [advancedOpen, setAdvancedOpen] = useState(false);
const eraserInstalled = useFeaturesStore((s) => s.isToolInstalled("erase-object"));
const featuresLoaded = useFeaturesStore((s) => s.loaded);
const fetchFeatures = useFeaturesStore((s) => s.fetch);
useEffect(() => {
fetchFeatures();
}, [fetchFeatures]);
const onChangeRef = useRef(onChange);
useEffect(() => {
onChangeRef.current = onChange;
@@ -40,8 +31,6 @@ export function TransparencyFixerControls({
onChangeRef.current({ defringe, outputFormat, removeWatermark });
}, [defringe, outputFormat, removeWatermark]);
const toggleDisabled = featuresLoaded && !eraserInstalled;
return (
<div className="space-y-3">
<p className="text-xs text-muted-foreground">
@@ -55,9 +44,7 @@ export function TransparencyFixerControls({
<div>
<p className="text-xs font-medium">Remove Watermark</p>
<p className="text-[10px] text-muted-foreground">
{toggleDisabled
? "Requires Object Eraser bundle"
: "Detect and remove semi-transparent watermarks"}
Detect and remove semi-transparent watermarks
</p>
</div>
</div>
@@ -65,11 +52,10 @@ export function TransparencyFixerControls({
type="button"
data-testid="remove-watermark-toggle"
aria-pressed={removeWatermark}
disabled={toggleDisabled}
onClick={() => setRemoveWatermark(!removeWatermark)}
className={`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${
removeWatermark ? "bg-primary" : "bg-muted"
} ${toggleDisabled ? "opacity-50 cursor-not-allowed" : ""}`}
}`}
>
<span
className={`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${