ComfyUI Node

MX_HSVThresholdMask

Select pixels by color, not by prompting

By Intersection98·Created 2 years ago·Updated 2 years ago· 13
MX_HSVThresholdMask
  • image
  • IMAGE
low_threshold0.2
high_threshold0.7
hsv_channel

HSVThresholdMask is the color-keying node in the MX pack: it builds a mask from every pixel whose hue, saturation, or value falls inside a range you pick. It's the ComfyUI version of Photoshop's "select color range" - point it at the sky, the grass, or a character's outfit, and out comes a white/black mask of everything that matches.

It's part of Intersection98/ComfyUI-MX-post-processing-nodes, and it pairs naturally with the pack's MX_AlphaBlend (composite through the color mask) or with inpainting flows that want a rough selection without a segmentation model.

How it works

It converts the image to HSV and runs cv2.inRange on a single chosen channel. The channel is where the design gets interesting: pick hue and you select by color (robust to lighting), pick saturation and you select colorful-vs-gray areas, pick value and you select by brightness. The 0–1 threshold floats are scaled per channel before use - hue thresholds multiply by 180, saturation and value by 255 - so a low_threshold of 0.2 and high_threshold of 0.7 on the hue channel covers roughly the 36°–126° slice of the color wheel. The output is a single-channel mask tensor, white where pixels are in range, black elsewhere.

The inputs that matter

  • image - your IMAGE tensor.
  • hsv_channel - hue, saturation, or value. Hue is the one you'll reach for most for color-based selection.
  • low_threshold / high_threshold - 0 to 1, defaults 0.2 / 0.7. The range of the channel to keep. The subtlety: hue is a circle (red sits at both 0 and 1), so a range like 0.9–0.1 that wraps around the wheel isn't expressible here - you'll need a second pass with inverted logic for that case.

Output is a single-channel IMAGE tensor shaped (B, H, W) - a mask, not a viewable color image. Convert with MaskToImage if you want to preview it, which is exactly what the pack's example workflow does.

Install

Standard MX pack install. ComfyUI Manager (search MX or ComfyUI-MX-post-processing-nodes), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Intersection98/ComfyUI_MX_post_processing-nodes
cd ComfyUI_MX_post_processing-nodes
pip install -r requirements.txt

Restart ComfyUI; it appears under postprocessing/Masks. No models - OpenCV does the work.

Where people get burned

Three classic traps. First, the hue circularity problem above: red objects straddle the 0/1 wrap, so a naive range misses half the red. Second, the defaults are wide (0.2–0.7 covers a huge slice), so your first mask will almost always include more than you intended - narrow the range and expect to iterate. Third, real-world colors have noise: even a "clean" selection picks up speckles, and there's no built-in blur or dilate to clean it up - route the output through a mask blur/feather node if you need a soft edge. If you've tried ControlNet and want something cheaper that needs no model at all, this is the node: it's instant, deterministic, and re-runs in a fraction of a second while you dial in the range.

Categorypostprocessing/Masks

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
low_thresholdFLOAT0.20–1
high_thresholdFLOAT0.70–1
hsv_channelCOMBO3 options: hue, saturation, value

Outputs (1)

NameTypeDescription
IMAGEIMAGE