InRange (hsv)
Chroma-key a color range out of an image — InRange (hsv)
- rgb_image
- color_a
- color_b
- hue_mode
- IMAGE
InRange (hsv) is OpenCV's inRange color thresholding, wrapped for ComfyUI and done properly in HSV instead of the RGB space people usually try first. You give it two colors that define a range, and it returns a black-and-white mask of every pixel whose color falls inside that range. It's the node you reach for when you want to segment by color - a green screen, a specific object hue, a background tint - without training anything.
Doing it in HSV is the right call, and it's why you'd use this over a naive RGB comparison. RGB distances don't match how humans perceive color: two "reds" can be far apart in RGB while looking identical. HSV splits color into hue (what color), saturation (how colorful), and value (how bright), so you can select "all reddish pixels, roughly this vivid, roughly this bright" with two color bounds. The pack even has a SampleColorHSV node to pull representative colors out of an image, and ColorToHSVColor to convert an RGB color into the HSV_COLOR type this node wants.
How it works
The image is converted RGB→HSV (with hue scaled 0-179, OpenCV's convention) and then thresholded with cv.inRange between color_a and color_b. Both bounds are inclusive. The clever part is how it handles hue, which is circular: hue 0 and hue 179 are both red, so a naive min..max range across the seam selects the wrong arc. That's what the hue_mode input is for (see the companion "Hue Mode (InRange hsv)" node) - it decides whether to do a single check, split the range across the seam, ignore hue entirely, or pick the smallest/largest arc between the two colors. Saturation and value always take the inclusive min/max of the two colors' bounds.
Inputs and outputs
rgb_image- the IMAGE to threshold.color_a,color_b- two HSV_COLOR values defining the range. Make them withColorToHSVColor(from an RGB color) orSampleColorHSV.hue_mode- an IR_HUE_MODE value, wired from the "Hue Mode (InRange hsv)" node.- Output: one IMAGE, the threshold - white where the pixel is in range, black elsewhere. Feed it into masking nodes, a
Color Clip, or use it as a mask for compositing.
Install
Part of bmad4ever/comfyui_bmad_nodes. Via ComfyUI Manager, search "comfyui_bmad_nodes" ("Bmad Nodes"), install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
Restart ComfyUI afterward. Needs opencv-python; no model files.
Common issues
Three things bite. First, the hue_mode socket is a custom type - you can't type a value into it, you have to wire in the "Hue Mode (InRange hsv)" node; if the socket stays empty, the node won't run. Second, hue wrapping: if you're selecting a range that crosses the 0/179 seam (any red-to-purple span), leave the hue mode on SMALLEST or SPLIT, because a plain single check will select the wrong side of the wheel. And third, remember HSV saturation/value variance - real-world "green screen green" isn't one value, it's a fuzzy ball in HSV space, so make the range generous in saturation and value or you'll get holes in the mask.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| rgb_image | IMAGE | — | |
| color_a | HSV_COLOR | — | |
| color_b | HSV_COLOR | — | |
| hue_mode | IR_HUE_MODE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |