Nodes/ComfyUI-JNK-Tiny-Nodes/Get One Alpha Layer JNK
ComfyUI Node

Get One Alpha Layer JNK

The single biggest cutout, noise and all the rest dropped

By AljnkΒ·Created about a year agoΒ·Updated 12 months agoΒ· 3
Get One Alpha Layer JNK
  • image
  • mask
  • rgb
  • mask
  • rgba

Get One Alpha Layer is the "keep just the main thing" half of the JNK pack's alpha-extraction pair. Feed it an image and a mask, and it finds every connected blob in that mask, then keeps only the largest one. Everything else - stray specks, distant small objects, the usual segmentation noise - gets discarded. Out the other side you get the subject on a white background, a clean mask, and an RGBA cutout.

That "largest only" behavior is the whole point, and it's the difference between this and Get All Alpha Layers (which keeps every region that clears a size bar). This one is for the common case: you've got a rough mask of a single subject, possibly polluted with noise, and you want one tidy cutout without hand-editing the mask. A quick pass with the noise-suppression built in.

How it works

Same machinery as its sibling: cv2.connectedComponentsWithStats breaks the mask into connected regions, each is checked against an area threshold (any region below 1% of the largest is dropped as noise), and then - the key step - among the survivors, only the single largest region is kept. The RGB output composites the image's pixels onto white through that region mask; the RGBA output carries the mask as alpha; the mask output is the cleaned single-region mask you could reuse elsewhere. It also handles batches, applying a single mask to a whole image batch or pairing mask and image batches one-to-one.

Inputs and outputs

  • image - the IMAGE whose pixels you want.
  • mask - the MASK marking foreground.

Outputs: rgb (subject on white), mask (cleaned, single-region), rgba (with alpha).

Installing it

Pack install: search JNK in ComfyUI Manager, or

cd ComfyUI/custom_nodes/
git clone https://github.com/Aljnk/ComfyUI-JNK-Tiny-Nodes.git

Requires opencv-python - the first line of the pack's requirements.txt. If Manager didn't auto-install deps, pip install opencv-python and restart.

Where people get burned

Same pair of surprises as Get All Alpha Layers. One: it writes a debug_regions.png into ComfyUI's working directory every run - a colored map of the regions it found. Not a problem, just don't go hunting for the source of a mystery PNG. Two: if no region clears the area threshold, you don't get an error - you get a white RGB, a zero mask, and an empty RGBA. That reads like a broken node until you realize the mask was too fragmented or the subject too small relative to the canvas. And remember the name means what it says: if your mask legitimately contains two equal-sized subjects, this node picks one and silently discards the other. When you need both, that's what Get All Alpha Layers is for.

CategoryπŸ”§ JNK

Inputs (2)

NameTypeDefaultDescription
imageIMAGEβ€”
maskMASKβ€”

Outputs (3)

NameTypeDescription
rgbIMAGEβ€”
maskMASKβ€”
rgbaIMAGEβ€”