CV Get CCM Matrix
Pull the colour matrix out of a fitted model
- ccm_model
- ccm_matrix
Colour calibration with a ColorChecker gives you a model - a fitted transform that you apply to images. Sometimes what you actually want is the matrix itself: to look at it, to export it, to check it for sanity, or to use it somewhere else entirely. This node hands you that array.
It's the read-out half of the ccm family in bmad4ever's ComfyUI CV (bmad4ever/comfyui_cv, a fork of Gerold Meisinger's opencv-comfyui), which wraps cv2.ccm - a contrib module behind a class-based API, so it needed a hand-written node rather than the pack's auto-generated raw cv2.* wrappers.
The node
ccm_model in - the fitted model socket from CV Create CCM Model (which takes detected patches from CV Detect Color Checker). ccm_matrix out - an NPARRAY that is either:
- 3×3 for
CCM_LINEAR(a straight matrix, no offset), or - 4×3 for
CCM_AFFINE(with an offset term).
Which one you get is decided back in the fitting node's ccm_type, not here. So read the shape before you assume a 3×3, and note that the affine form is not something you can hand to a node that wants a plain colour transform.
What you do with it
Read it. Connect an inspect node and eyeball it. A plausible linear CCM looks like a matrix with a dominant diagonal and modest off-diagonal terms - the sensor's channels are mostly already right, and you're correcting the cross-talk. A matrix full of huge numbers means the fit fought the data, usually because the chart detection was poor or the patches were clipped. This is the kind of five-second sanity check that saves you from a whole batch of subtly wrong colours.
Reuse it. The matrix is a plain array, so it's portable: apply it as a linear transform elsewhere in the graph (the HDR playground does exactly this with a parsed matrix in RGB space), save it, or bake it into an external pipeline. Once you've calibrated a camera once, re-fitting it for every session is wasted work - grab the matrix and apply it.
Compare fits. Fit the same patches with CCM_LINEAR and with CCM_AFFINE, print both matrices, and read the loss from CV Get CCM Loss to decide whether the extra offset row is earning its keep.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Or find ComfyUI CV in ComfyUI Manager. Python ≥ 3.12 and a recent ComfyUI on the V3 node API. Example: workflows/11_color_correction_basic.json walks detect → fit → apply, and this node sits on the inspect side of it.
Common issues
The nodes don't appear at all. This is the contrib-wheel trap, and it's specific enough to repeat: the pack depends on opencv-contrib-python-headless, and all the OpenCV wheels share one site-packages/cv2. Installing opencv-python (non-contrib) over it silently empties the contrib submodules, and cv2.ccm and cv2.mcc are contrib. The pack ships tools/repair_opencv_contrib.py - --check diagnoses, --apply repairs - but the shortest fix is to reinstall the contrib wheel last.
A 4×3 matrix where you expected 3×3. You fitted an affine model. Change ccm_type in the fitting node.
The matrix looks wild. Look upstream first - a mis-detected chart, or patches that were blown out or crushed, produce a fit that's numerically fine and physically nonsense. Check the detector's found and the loss before believing the matrix.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| ccm_model | CCM_MODEL | Fitted model from 'Create CCM Model'. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| ccm_matrix | NPARRAY | — |