Nodes/opencv-comfyui/OpenCV illuminationChange_0
ComfyUI Node

OpenCV illuminationChange_0

Synthesize lighting changes with a mask — the data-augmentation trick

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV illuminationChange_0
  • src
  • mask
  • dst
  • nparray
alpha
beta

illuminationChange_0 is a wrapper around cv2.illuminationChange, and it does something pretty specific: it takes an image plus a mask and simulates what the region inside the mask would look like under different lighting. Not brightness in the "slider up" sense - it fits a local photometric model of the masked area and re-renders it as if the light source had moved or a shadow had shifted across the scene. Same family as OpenCV's seamless-cloning utilities, and honestly a fancy, physically-motivated trick rather than a filter you twiddle by eye.

Why would you reach for this in ComfyUI? The honest answer: it's a data-augmentation and research tool, not a creative filter. If you're building a training dataset - faces with consistent ID across lighting conditions, product shots where you want the background to re-light while the object stays put - you can use this to synthesize illumination variation from one source image. If you're fine-tuning a model and want it to stop caring about lighting, generating these variants is cheap and deterministic. For a one-off "make this area brighter" job, you'd instead reach for a gamma or exposure node; this is not that.

How it works. You give it src (the image, NPARRAY) and mask (also NPARRAY - the region where the lighting change applies). Inside the masked area it computes a local illumination model and reconstructs the region as if the lighting differed, then blends back in. The two tuning knobs:

  • alpha (FLOAT) - how strongly the change applies to the masked region.
  • beta (FLOAT) - a second influence weight; in OpenCV's own implementation both control the local illumination estimation (OpenCV's default example uses 0.2 and 0.4).

Both are floats that land in the roughly 0–2 range in practice; start around 0.2/0.4 and move them one at a time, because the effect is subtle-to-weird and hard to predict from the numbers.

dst is the usual optional out-parameter - leave it unwired and take the nparray output.

Output. One nparray (NPARRAY): the image with the relit region. Back to a ComfyUI IMAGE via Nparrays2Image.

Installing. This is one node in the opencv-comfyui pack. ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Restart, and it's under image/OpenCV.

Where people get burned. The mask has to be a real NPARRAY image, not a ComfyUI MASK tensor - you can't wire a mask output straight in. Convert your Comfy image with Image2Nparray, and if your mask came from a Comfy MASK node, you'll need to get it into the same BGR/uint8 nparray form first. And if your src isn't a 3-channel color image, the function may throw the classic img.type() == CV_8UC1-style assertions - those are OpenCV complaining about channel/type mismatch, and the README's guidance is to check what you're feeding it and convert with cvtColor (6 = BGR2GRAY, 8 = GRAY2BGR) as needed. Also remember the pack rule: batch size 1 only.

Why _0 and not _1? This pack numbers OpenCV's overloads. illuminationChange_1 has the identical signature and identical generated code - same cv2.illuminationChange call. Pick whichever; there's no difference between them.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
maskNPARRAY
alphaFLOAT
betaFLOAT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY