BuildColorRangeHSV (hsv)
Point at a color, get the mask range for it — statistically
- samples
- HSV_COLOR
- HSV_COLOR
- IR_HUE_MODE
Color-based masking in OpenCV needs a hard answer to a soft question: which orange is "the" orange? No single pixel represents the color you mean - there's shadow, highlight, noise. BuildColorRangeHSV answers it by sampling: you give it a handful of pixels that are "definitely the color I want," and it computes a statistical range around them, in HSV, that the pack's InRangeHSV node can use to build a mask.
It's the approachable member of the color-range family. Its advanced sibling expects you to write expressions; this one gives you a percentage and a choice of statistics. If your goal is "mask everything roughly this color, from a few sample clicks," this is the node you want.
How it works
samples- anHSV_SAMPLESobject from the pack's SampleColorHSV node. Click a few points on your target color in that node and you've got a sample set.percentage_modifier(default 50, range 1–100) - how wide the range is. Higher = more forgiving, but it'll catch neighbor colors too.interval_type- the statistics that turn samples into bounds:- median to extremes interpolation (default) - grows the range outward from the median; the forgiving, sensible default.
- average ± 3× max deviation - hugs the samples tightly; good when your color is consistent.
- average ± 2× standard deviation - statistical spread; similar idea to the above with a different tail.
- sample percentage centered at median - a quantile-based band around the median.
The node computes a [lower, upper] interval for hue, saturation, and value, then does the OpenCV housekeeping: hue is 0–180 here (not 360), a range crossing the wrap point gets flagged for splitting, and sat/val get clamped to 0–255. That housekeeping is exactly what the three outputs carry.
The outputs - wire all three
HSV_COLORlower andHSV_COLORupper - the two ends of the range.IR_HUE_MODE- the flag that tells InRangeHSV whether the hue interval wraps around zero and needs to be handled as two ranges.
These three go together into InRangeHSV (or the pack's Color Clip) to produce the actual mask. Forgetting the IR_HUE_MODE wire is the classic mistake - hue is where color masks fall apart, and that flag is what keeps the red/purple boundary sane.
Install
Part of bmad4ever/comfyui_bmad_nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
Restart, or ComfyUI Manager → search comfyui_bmad_nodes. OpenCV does the heavy lifting (opencv-python~=4.8.1.78 pinned); no models.
Gotchas
percentage_modifier means something slightly different for each interval_type - it's a percentage of what depends on the method, so compare results when you switch. Start with the default method and tune the percentage first; only change interval_type if the default's shape is wrong for your data. And the samples rule everything: sampling one bright highlight pixel vs. a patch of mid-tone pixels will give you very different ranges, so sample like you mean it - a few points across the color, not one lucky click.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| samples | HSV_SAMPLES | — | |
| percentage_modifier | INT | 501–100 | — |
| interval_type | COMBO | median to extremes interpolation | 4 options: median to extremes interpolation, average +- 3x max deviation, average +- 2x standard deviation, sample percentage centered at median |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| HSV_COLOR | HSV_COLOR | — |
| HSV_COLOR | HSV_COLOR | — |
| IR_HUE_MODE | IR_HUE_MODE | — |