EqualizeHistogram
Stretch a washed-out image before you threshold it
- src
- IMAGE
A flat, low-contrast grayscale image is a nightmare for thresholding - every value lands in the middle, and no threshold cleanly separates foreground from background. EqualizeHistogram fixes that with OpenCV's classic histogram equalization: it stretches the brightness distribution so dark values spread dark and bright values spread bright, turning a murky blob into something with real contrast.
It lives in the pack's CV/Thresholding section for a reason: it's prep. You equalize first, threshold second, then feed the binary result to Contours.
How it works
- src - an
IMAGE. - Output - the equalized image.
The node flattens the input to grayscale via OpenCV (tensor2opencv with 1 channel), runs cv.equalizeHist, converts back to a 3-channel RGB image (the gray values duplicated), and returns that as an IMAGE. So the output is still a full image, just one whose histogram has been spread out. Because it converts to gray internally, color information is irrelevant to the result - this is a luminance operation.
Two practical notes:
- Output is RGB. Even though the math is grayscale, the returned tensor has 3 channels. If your next node wants a true 1-channel gray, run it through
ConvertImg(GRAY) first. - No parameters. There's a single
srcinput - the algorithm picks its own transformation. If you want controlled contrast instead of automatic, the pack's CLAHE node (which adds clip limits and tile grids) orThreshold-family nodes are the tunable options.
When to reach for it
- A scan or render where dark objects are vanishing into a gray background. Equalize, then threshold, and the shapes separate cleanly.
- Before
Contours: the node's docs tell you to threshold before contour-finding, and equalization makes that threshold actually work. - As a quick contrast fix on masks that are too "soft" - though for masks you usually want the more surgical
CLAHE.
The honest caveat: equalization amplifies noise along with signal. On clean synthetic masks it's a strict win; on noisy photos it can make thresholding more finicky. Test it both ways - it's one node to add or bypass.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
or install "comfyui_bmad_nodes" via ComfyUI Manager and restart. OpenCV-only; no models. If your CV chain produces washed-out thresholds, put this node in front of the threshold step and watch the separation improve.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| src | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |