Cutout Edge Refinement, Explained: Guided Filtering, Color Correction, and Morphology
Published: 2026-11-06
Why Edge Refinement Is Necessary
Even the best segmentation model can't produce edges that perfectly hug the true outline of objects in the source image. The reasons: limited model input resolution (e.g. 320×320), so edges "detach" when the mask is upsampled to full size; annotation errors of 1–2 pixels in the training data itself; and low confidence in low-contrast regions (dark hair against a dark background).
Edge refinement is the post-processing pipeline that closes these gaps. This site uses a six-step pipeline, with each step addressing a specific edge problem.
Technique 1: Connected-Component Analysis
A segmentation result can contain a lot of debris: tiny noise specks in the background (only a few pixels each) and fragments broken off the subject.
Debris removal: delete connected components smaller than 1/500 of the largest foreground region — these are almost always noise
Hole filling: fill background regions that don't touch the image border (i.e. "holes" inside the subject) back into the foreground. For example, if the gap between chair legs is too narrow, it gets misclassified as an interior hole
Technique 2: Morphological Edge Control
Hole filling dilates the outline outward, which can leave a stray halo of background pixels around the subject. Erosion pulls it back in.
Dilate: expand the foreground by N pixels — used to close narrow gaps in the outline
Erode: shrink the foreground by N pixels — used to remove leftover background halo at the edges
Opening: erode then dilate — removes tiny protrusions
This site's Edge Adjust feature is built on this principle: positive values dilate (restoring over-cut areas), negative values erode (shrinking the halo).
Technique 3: Guided Filter
This is the core of edge refinement. A guided filter is an edge-preserving filter that uses the original image as a "guide," snapping the coarse segmentation mask onto the edges in the original image.
Intuition
Imagine the mask says "this pixel is about 70% foreground," while the edge gradient in the original image says "there's a crisp object contour right here." The guided filter turns that 70% into a more precise value, aligning the mask's edge with the object's actual outline.
How it works
Within a local window, compute the linear relationship between the original image's luminance and the mask
Assume that within this window, output = a × guide + b
Solve for the coefficients a and b so the output stays close to the mask while following the guide's gradients
Parameters on this site
We use a guided filter with radius 2–6 (adapted to image size), running at resolutions up to a 1024px long edge; it takes about 100 ms.
Technique 4: Color Snap Correction
Edge pixels after segmentation are often a blend of foreground and background colors. For example, the edge of golden hair may carry a residue of the blue background.
How it works
Sample color statistics from low-alpha regions along the four image borders to build a background color reference
Build a foreground color reference from high-confidence interior regions
For every pixel in the transition band (alpha 0.15–0.9), compute its Euclidean distance to the foreground and background references
Closer to the background → lower the alpha (push toward transparent); otherwise keep or raise it
Edge Cleanup on this site
This feature is based on exactly this principle. The strength setting controls how aggressive the correction is — the larger the color-distance gap between the two sides, the stronger the correction weight. Start at 55; if the result isn't clean enough, raise it to 70.