ComfyUI Node
CV Image Moments
Measures every frame of a batch with cv2.moments over the IMAGE INTENSITY rather than an outline - Hu's original density formulation, and the case the contour nodes cannot reach. Two regions with identical outlines but different internal shading are the SAME shape to 'CV Shape Moments' and different shapes here. Outputs mirror 'CV Shape Moments' one-for-one so the two are interchangeable downstream. Feed it crops from 'Crop By Masks' / 'Crop By BBoxes' to measure regions of one scene. Beware: intensity moments are NOT invariant to exposure and a non-zero background is fatal - see the weighting tooltip. Zero frames is a valid result, not an error.
CV Image Moments
- images
- centroids
- mass
- angles
- eccentricities
- axes
- hu_moments
- count
- orientations
- chirality
- pose_confidence
◄weightingintensity, peak-normalized►
Categoryimage/CV/moments
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| images | NPARRAY,IMAGE,MASK | Frames to measure, one row of output per frame. Reduced to a single channel (luminance for a colour picture) because cv2.moments rejects a 3-channel array. 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. | |
| weighting | COMBO | intensity, peak-normalized | Which density function the moments integrate. 'intensity' is Hu's original formulation and cv2's default (mass = pixel value), so a shaded region is a different shape from a flat one. Hu moments are NOT invariant to a brightness gain, so 'peak-normalized' (divide by the frame's own maximum) is the default: it more than halved the error of a x0.5 exposure change in testing (I1 0.0394 raw -> 0.0146). It does NOT fully remove the effect - dimming also shrinks the effective support of a soft-edged region, and no normalization can fix that. 'binary' ignores the values and uses the silhouette, which is the closest thing to what the contour nodes measure - but beware, it treats EVERY non-zero pixel as part of the shape, so any background haze swallows the whole frame. |
Outputs (10)
| Name | Type | Description |
|---|---|---|
| centroids | NPARRAY | (N,1,2) float32 centre of mass per frame - plugs into 'CV Draw Points' / 'Draw Labels'. This is the INTENSITY centroid, so shading moves it. |
| mass | NPARRAY | (N,) float32 the m00 moment: the SUM OF THE PIXEL VALUES, not an area (with 'binary' weighting it is the count of non-zero pixels, which is an area). |
| angles | NPARRAY | (N,) float32 orientation of the major axis in degrees, [-90, 90), from the +X axis with Y pointing DOWN. Meaningless for a radially symmetric distribution (eccentricity ~ 0). |
| eccentricities | NPARRAY | (N,) float32 elongation in 0-1: 0 = radially symmetric, -> 1 = a line. From the central-moment eigenvalues. |
| axes | NPARRAY | (N,4) float32 major-axis segments (x1, y1, x2, y2) through each centroid, 2 standard deviations long per side - plugs into 'CV Draw Segments'. |
| hu_moments | NPARRAY | (N,7) float32 log-scaled Hu invariants, -sign(h)*log10(|h|) per component, matching 'OpenCV Shape Moments'. Invariant to translation, scale and rotation of the intensity field - but NOT to a brightness change. |
| count | INT | — |
| orientations | NPARRAY | (N,) float32 canonical orientation, 0-360, with the head told from the tail by the third-order moments (unlike 'angles', which is only defined mod 180). MEANINGLESS when pose_confidence is ~0. |
| chirality | NPARRAY | (N,) float32 signed handedness from the 7th Hu invariant, the only one whose sign changes under reflection (CV HuMoments docs; Hu 1962) and the one usually discarded as too small and too noisy to trust - hence the sign(h7)*|h7|**0.25 rescaling. The sign flips under reflection and survives rotation and scale. NOTE the magnitudes here are far smaller than for a hard-edged silhouette - a smooth intensity field measures around 1e-5 where an 'F' glyph measures 0.02-0.05 - so the matcher's 'min_chirality' gate needs a much lower value on this path. |
| pose_confidence | NPARRAY | (N,) float32 how well-defined 'orientations' is (the normalized third moment along the major axis). Judge it relative to the other frames in the batch, not against the silhouette thresholds quoted on 'OpenCV Shape Moments'. |