Nodes/comfyui_cv/CV Photometric Align (Gain/Bias)
ComfyUI Node

CV Photometric Align (Gain/Bias)

Matches one image's exposure and white balance to another's by fitting a per-channel gain and bias (source * gain + bias ~ reference) - the photometric counterpart of a geometric registration. Use it when two shots of the same scene were taken minutes (or one auto-exposure decision) apart: a clean background plate against the take, a burst frame against its neighbour, a flat field against the shot it corrects. The fit is ROBUST: pixels whose content changed - a subject that was not there in the plate, a moving object, a specular flash - are outliers and are trimmed away, so the gain describes the LIGHT, not the difference. Saturated pixels are dropped too (they carry no gain information). The pixels the fit kept come back as 'inlier_mask', which is a ready made 'what is unchanged here' mask. Fails soft (rule of the pack): a featureless or degenerate pair returns found=false with gain 1 / bias 0 and the source untouched.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Photometric Align (Gain/Bias)
  • source
  • reference
  • mask
  • aligned
  • gain
  • bias
  • inlier_mask
  • residual
  • found
modelgain + bias
scopeper channel (also fixes white balance)
inlier_fraction0.50
iterations3
Categoryimage/CV

Inputs (7)

NameTypeDefaultDescription
sourceCOMFY_MATCHTYPE_V3Image to correct - its exposure is changed to match the reference. Echoed back in the same type (IMAGE/MASK/NPARRAY). 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.
referenceNPARRAY,IMAGE,MASKImage whose exposure/white balance is the target. Same size and channel count as the source; it is never modified. 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.
modelCOMBOgain + biasWhat to fit. 'gain + bias' handles an exposure change plus a black-level/flare shift (the usual case). 'gain only' is the pure exposure/ISO model. 'bias only' is an additive offset, e.g. stray light added to one shot.
scopeCOMBOper channel (also fixes white balance)Per channel gives each of B, G, R its own gain and bias, which also corrects a white-balance drift. One shared fit is safer when the images have few unchanged pixels, because all channels then pool their evidence.
inlier_fractionFLOAT0.500.05–1Fraction of pixels kept as inliers at each refit. Set it BELOW the fraction of the frame that is genuinely unchanged (0.5 tolerates a subject covering half the frame). 1.0 disables the trimming and gives a plain least squares.
iterationsINT31–20Refits after the initial difference-based inlier selection. 3 is enough for a photometric drift; more only matters when the first selection was poor.
maskoptNPARRAY,MASKOptional region to fit ON (non-zero pixels), for when you already know where the unchanged background is. The trimming still runs inside it. 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.

Outputs (6)

NameTypeDescription
alignedCOMFY_MATCHTYPE_V3The source with gain/bias applied, in the source's own type and dtype (integer types are rounded and clipped). Identical to the input when found=false.
gainNPARRAYfloat64 (C,) multiplier per channel, 1.0 where nothing was fitted.
biasNPARRAYfloat64 (C,) offset per channel, in the input's own units (0-255 for uint8), 0.0 where nothing was fitted.
inlier_maskNPARRAYuint8 [H,W] 255 where the pixel was an inlier in EVERY channel, i.e. where the two images show the same thing under the fitted lighting. All zeros when found=false.
residualFLOATMedian absolute residual over the inliers after the fit, in input units - how well the two images agree once the light is accounted for.
foundBOOLEAN