π― YFG Image To Contrast Mask
Turn an image into a contrast mask for inpainting or compositing
- image
- IMAGE
- MASK
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'smaskinput, 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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| low_threshold | INT | 11β255 | β |
| high_threshold | INT | 2551β255 | β |
| blur_radius | INT | 11β32768 | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | β |
| MASK | MASK | β |