← JuanJuan Tools · Guides

Cutout Edge Refinement, Explained: Guided Filtering, Color Correction, and Morphology

Published: 2026-11-06

Why Edge Refinement Is Necessary

Segmentation maskRough + jaggedGuided filterEdge snappingColor correctionStrips bg colorMorphologyShrink + featherRefined resultSmooth + accurate── Refinement pipeline: ~200 ms ──Debris removalHole fillingEdge cleanupEdge adjust ±pxSix refinement steps turn a segmentation mask into a high-quality cutout
Raw maskJagged + burrsRefinedSmooth + accurateGuided filtering snaps the jagged mask onto the object's true contour

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.

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.

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

  1. Within a local window, compute the linear relationship between the original image's luminance and the mask
  2. Assume that within this window, output = a × guide + b
  3. 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

  1. Sample color statistics from low-alpha regions along the four image borders to build a background color reference
  2. Build a foreground color reference from high-confidence interior regions
  3. For every pixel in the transition band (alpha 0.15–0.9), compute its Euclidean distance to the foreground and background references
  4. 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.

The Complete Refinement Pipeline

The order this site uses:

  1. Connected-component analysis: debris removal + hole filling
  2. Morphological edge control: 4-pixel erosion + 3×3 feathering
  3. Guided filter: snap the mask onto the original image's gradients
  4. Color snap correction: fix transition-band pixels
  5. (Optional) Edge Cleanup
  6. (Optional) Edge Adjust: ±4 px

The whole pipeline runs in about 200 ms at 1024px resolution and is completely invisible to the user.

Try it free — remove a background now →