Nodes/opencv-comfyui/OpenCV equalizeHist_0
ComfyUI Node

OpenCV equalizeHist_0

The fastest way to fix a flat, washed-out image in ComfyUI

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV equalizeHist_0
  • src
  • dst
  • nparray

Ever generated an image that's technically fine but looks flat - no deep blacks, no crisp highlights, everything sitting in a gray mush in the middle? That's a contrast problem, and equalizeHist is the classic no-thinking fix. Feed it a grayscale image and it remaps the pixel values so the darkest grays spread toward black and the lightest toward white, stretching the histogram to fill the whole range. One wire, one node, instant "punch."

This node is part of opencv-comfyui (geroldmeisinger/opencv-comfyui), a pack that auto-generates a ComfyUI node for basically every standalone OpenCV function. It's a direct wrapper around cv2.equalizeHist(src, dst=None). Nothing fancy, no model involved - pure histogram math on the pixels. That's also the honest positioning: this whole pack sits in the deterministic post-processing layer, not the diffusion layer. It runs locally, instantly, and never touches your model.

How it works

Histogram equalization computes the cumulative distribution of gray levels in the image, then remaps each level so the output histogram is roughly uniform. The math was designed for grayscale medical and satellite imagery, but its party trick is exactly the "auto contrast" you want on a flat render. The catch: OpenCV's equalizeHist only works on single-channel 8-bit grayscale. Feed it a normal 3-channel BGR image and you get the pack's trademark error:

error: (-215:Assertion failed) img.type() == CV_8UC1 in function

Inputs and outputs

The node is about as bare as they come:

  • src (NPARRAY) - your image, in OpenCV's format. Must be grayscale.
  • dst (NPARRAY, optional) - this is an OpenCV out-parameter. Leave it unconnected; the node returns the result anyway. That's true for every node in this pack - the README explicitly tells you to avoid the optional dst inputs.
  • Output: nparray - the equalized image, still grayscale, still uint8.

Wiring it up

The pack deliberately refuses to work on ComfyUI's IMAGE type. OpenCV works on nparray (BGR, uint8, (H,W,C)); ComfyUI works on torch tensors (RGB, float 0-1, batched). So the minimal graph is:

  1. Image2Nparray - converts your IMAGE to a BGR nparray.
  2. cvtColor with code 6 (BGR2GRAY) - equalizeHist needs grayscale.
  3. This node.
  4. cvtColor code 8 (GRAY2BGR), then Nparrays2Image to get back to a normal IMAGE.

If you want to equalize a color image without wrecking its hue, split to HSV and run it on the V channel only - but note this pack has no split/merge nodes, so extractChannel is your workaround, and it gets fiddly fast.

Install

Install via ComfyUI Manager (search "opencv-comfyui"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Then restart ComfyUI. The pack needs opencv-contrib-python, numpy, and torch (all in its requirements.txt), and you may need pip install opencv-contrib-python yourself. No model files to download - everything is local. The author's own warning for this pack: "Expect dragons!" It's auto-generated from OpenCV's type stubs, so the nodes are ugly and the knobs are raw numbers.

Common issues

The -215 assertion above is the one you'll actually hit - fix it with cvtColor code 6. Also remember Image2Nparray only accepts batch_size 1, so run it on a single image, not a batch. And don't expect miracles on an image that's already high-contrast - equalization mostly pays off when the histogram is bunched up.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY