Nodes/ComfyUI CV/cv2.ccm.gammaCorrection
ComfyUI Node

cv2.ccm.gammaCorrection

The gamma node with the same name as the other gamma node

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.ccm.gammaCorrection
  • src
  • nparray
◄gamma0.0000►

Gamma is a power curve, out = in ^ k, and it's the operation people should reach for and usually don't: brightness sliders are additive and clip highlights, while a gamma curve lifts or crushes midtones and leaves white alone. This node is OpenCV's contrib ccm module's version of that curve, exposed as a raw wrapper in comfyui_cv.

Before you wire it up, know that the same pack ships a second node called gamma correction - cv2.intensity_transform.gammaCorrection, a different OpenCV module with a different signature. Two nodes, nearly the same name, meaningfully different behaviour. That's not the pack being sloppy; it's what "expose every cv2.* function faithfully" looks like when upstream has the same function name in two modules.

Which one do you want?

If you have an IMAGE and you want to brighten or darken midtones, you want the intensity_transform one. It's registered as type-preserving, so IMAGE in → IMAGE out and it drops straight into a graph. The pack's own example workflow (12_white_balance_and_tone.json) uses it with gamma 0.5 to lift shadows and gamma 1.8 to deepen them - a useful reference for the direction convention: below 1 brightens.

cv2.ccm.gammaCorrection is the module-specific helper for the colour-correction pipeline, and it lives in the pack under the image/CV/ccm category next to the CCM nodes. It is not type-preserving: its output is a plain NPARRAY, so it won't land on an IMAGE socket and you'll need CV Array → Image (or CV Array → Mask) to view or reuse it. That difference is the practical reason to pick one over the other.

Inputs and output

  • src (required) - the input. Accepts NPARRAY, IMAGE or MASK. Be aware of what the conversion does: an IMAGE arrives as uint8 BGR with values 0–255, a MASK as uint8 single-channel, and only frame 0 of a batch. If you want the curve applied to smooth float data, feed an NPARRAY (for instance via Latent → CV Array, which passes float values through untouched) rather than an image link.
  • gamma (required, default 0) - the exponent. Zero is not a gamma; that's just the widget's landing spot because OpenCV's stubs don't carry a default. Set a real number - 2.2 for a standard display-curve correction, or something near 1 for a gentle adjustment.

One output: nparray.

Where it fits

The CCM workflows in this pack go: detect a ColorChecker chart (CV Detect Color Checker), fit a model (CV Create CCM Model), apply it (CV Apply Color Correction), and inspect the matrix and the fit loss with the getter nodes. Gamma handling belongs on the ends of that pipeline - linearising input before a fit, or re-encoding output for display - which is why OpenCV puts a gamma helper in the module at all. If you're doing colour calibration with a chart, this is the node you'd reach for; if you're doing daylight-to-tungsten hobby colouring, you're in the wrong category and the intensity_transform node or a Color Balance node is what you actually want.

For context on the other two: xphoto also ships white-balance and tone nodes in this pack, and its three balancers are genuinely different algorithms rather than three settings on one dial.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv

Restart, or Manager → search "comfyui_cv". Python ≥ 3.12, a recent ComfyUI on the V3 node API, and - critically - the contrib build of OpenCV, because ccm is a contrib module:

pip install "opencv-contrib-python-headless~=5.0.0.93"

No models involved.

Common issues

The node isn't in your menu, but other cv2 nodes are. This one lives in a contrib submodule, and the registry only builds entries the installed OpenCV actually exposes. Installing plain opencv-python over a contrib wheel silently empties the shared site-packages/cv2 - the ordinary-looking symptom is exactly this, a few contrib nodes quietly missing. The pack ships tools/repair_opencv_contrib.py (--check, then --apply) for the diagnosis and fix.

The output won't connect to an IMAGE input. Correct - it's an NPARRAY. Add CV Array → Image.

It looks wrong going through an IMAGE link. The pipeline quantizes to uint8 in BGR and back. Gamma on 8-bit data throws away shadow precision, which is the region gamma exists to fix. Work in NPARRAY, or use the type-preserving sibling node.

It goes the wrong direction from what you expected. Flip the exponent - you probably want 1/k rather than k. The pack's own examples use 0.5 to lift shadows.

Categoryimage/CV/low-level/ccm

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASK - - - Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
gammaFLOAT0.0000-1e+38–1e+38 - - -

Outputs (1)

NameTypeDescription
nparrayNPARRAY—