Nodes/ComfyUI-YCNodes/Mask Smart Valley Split
ComfyUI Node

Mask Smart Valley Split

Split a joined mask along its waist — where two blobs are fused, cut the valley

By yichengup·Created 2 years ago·Updated 4 months ago· 47
Mask Smart Valley Split
  • mask
  • MASK
valley_depth_threshold0.5
pattern_check_range10
cut_width2

Two objects that touch become one blob in a mask, and segmentation doesn't always separate them. Mask Smart Valley Split is a heuristic for exactly that: it looks at the column-by-column density of the mask, finds the deepest "valley" - the narrowest, most pinched point between two fat regions - and cuts the mask there, splitting the blob in two along the pinch.

Think two people standing shoulder-to-shoulder, a wine bottle next to a glass, or two frames in a strip that got merged. The mask is one connected region, but your workflow needs two. This node guesses where the natural break is and makes it a clean, straight cut.

How it works

It projects the mask onto the x-axis - summing each column - smooths the profile to kill noise, finds the two dominant "peaks" (dense regions), then looks for the lowest point between them. That low point is the valley. If the valley is deep enough relative to valley_depth_threshold, the node erases a vertical strip cut_width pixels wide there, severing the connection. The output is a single mask that's been cut into what should be two pieces.

The three dials:

  • valley_depth_threshold (0.1–1, default 0.5) - how shallow a dip counts as a break. Lower = more aggressive splitting.
  • pattern_check_range (5–50, default 10) - how wide a neighborhood it inspects to decide a valley is real.
  • cut_width (1–10, default 2) - how thick the removed strip is. 2 is usually plenty.

Because the analysis is per-column, it's built for blobs that are fused along the vertical boundary - side-by-side objects. It will not separate a blob that's a single solid mass with no dip; if there's no genuine valley, it returns the mask unchanged rather than forcing a cut.

Output

One MASK - the split mask, same size as the input. You'll typically run Mask Split Filter after it (or use the pack's other splitter) to pull the two halves out as separate masks if you need them individually.

Install

Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes

Restart ComfyUI. Standard deps, no downloads. Under "YCNode/Mask".

Gotchas

This is a heuristic, not a segmentation model. If the pinch isn't visible in the column profile - two blobs fused along a horizontal seam, or a blob with three peaks - the algorithm either picks the wrong valley or declines to cut. valley_depth_threshold below 0.3 will start splitting things that are merely bumpy, so tune from the default down only when you see it refusing an obvious cut. And the cut is a straight vertical strip: you won't get a curved separation out of this. For arbitrary per-object separation you'd want an actual segmenter; for "there's a waist here, cut it," this does the job.

CategoryYCNode/Mask

Inputs (4)

NameTypeDefaultDescription
maskMASK
valley_depth_thresholdFLOAT0.50.1–1
pattern_check_rangeINT105–50
cut_widthINT21–10

Outputs (1)

NameTypeDescription
MASKMASK