Nodes/😸 YFG Comical Nodes/🐯 YFG Image To Contrast Mask
ComfyUI Node

🐯 YFG Image To Contrast Mask

Turn an image into a contrast mask for inpainting or compositing

By gonzaluΒ·Created 2 years agoΒ·Updated a day agoΒ· 29
🐯 YFG Image To Contrast Mask
  • image
  • IMAGE
  • MASK
β—„low_threshold1β–Ί
β—„high_threshold255β–Ί
β—„blur_radius1β–Ί

Masks are the invisible scaffolding of half of ComfyUI - they're how inpainting knows what to regenerate, how compositing decides what to keep, and how a lot of ControlNet-adjacent tricks gate their effect. The problem is that masks are usually something you draw, and drawing by hand is slow and imprecise. This node flips that: it derives a mask automatically from the brightness structure of an existing image, so "make the bright bits the mask" or "mask everything below this brightness" becomes a node, not a paint session.

It's the "Image To Contrast Mask" node from the YFG Comical pack (gonzalu/ComfyUI_YFG_Comical), an adaptation of code originally by the ComfyUI user XSS. It outputs both an IMAGE and a MASK, so you can use it either as a mask in the standard way, or as a gray image in anything that takes images.

How it works

The image gets converted to grayscale, then run through a simple piecewise threshold filter:

  • pixels above high_threshold β†’ white (255)
  • pixels below low_threshold β†’ black (0)
  • everything in between β†’ left as-is

So the defaults (low=1, high=255) leave the whole tonal range intact - not a hard threshold at all, just a grayscale map. Crank low_threshold up and everything darker than that snaps to black. Drop high_threshold down and the brights clip to white. The blur_radius option applies a Gaussian blur before the filter, which softens edges - critical if you're masking something organic and don't want a crunchy cutout.

The inputs that matter

  • low_threshold (1–255, default 1) - floor: anything below this becomes black.
  • high_threshold (1–255, default 255) - ceiling: anything above this becomes white.
  • blur_radius (1–32768, default 1) - the smoothing lever. This is the one you'll actually tune; big values blur aggressively.

Outputs

  • IMAGE - the same processed grayscale, as an image tensor (feed it to a SaveImage or use it as a mask-to-image input).
  • MASK - the proper mask tensor, ready for a KSampler's mask input, a MaskComposite, or whatever else eats masks.

Installing

Standard pack install: ComfyUI Manager β†’ search "YFG Comical", or

cd ComfyUI/custom_nodes
git clone https://github.com/gonzalu/ComfyUI_YFG_Comical

Restart ComfyUI. Note the pack-wide gotcha: several pack files import cv2/matplotlib without declaring them in pyproject.toml. If the whole pack fails to import, pip install opencv-python matplotlib and restart.

Where people get burned

The trap is expecting a hard black/white binary and getting soft grays instead - that only happens if low is high and high is low enough to force everything to an edge. If you want a true binary mask, set low_threshold and high_threshold close together (e.g. 100 and 140) so nothing lands in the middle. Also, this works on brightness, not edges: a bright subject on a bright background will not separate cleanly no matter how you tune it. For that job you want a proper segmentation tool, not a threshold.

Category🐯 YFG

Inputs (4)

NameTypeDefaultDescription
imageIMAGEβ€”
low_thresholdINT11–255β€”
high_thresholdINT2551–255β€”
blur_radiusINT11–32768β€”

Outputs (2)

NameTypeDescription
IMAGEIMAGEβ€”
MASKMASKβ€”