Skip to content
AI360Xpert
Beta

Contour Properties

Turn an outline into numbers: area from one moment, center from two ratios, and pointing direction from the spread of pixels around that center.

Area is M00 and the centroid divides first orders by area: triangle (0,0) (4,0) (0,3) gives area 6 and centroid (1.333, 1.0)
Area is M00 and the centroid divides first orders by area: triangle (0,0) (4,0) (0,3) gives area 6 and centroid (1.333, 1.0)

Why Does This Exist?

Detection hands you loops, but a robot gripper needs the center in millimeters and a sorter needs the area in square pixels. Contour properties are the integrals that convert outlines into those measurements: area, centroid, orientation, and the shape ratios that tell rods from disks. They cost one pass over the loop and need no training, which keeps them inside every real-time inspection pipeline.

This page covers raw and central moments, the centroid derivation, and the ratio descriptors. Hull-based concavity analysis continues in convex hulls, and fitted geometry in bounding shapes.

Think of It Like This

Balancing a cardboard cutout

Cut a wrench shape from cardboard and balance it on one fingertip: the balance point is the centroid, the only point where weight spreads evenly in all directions. Weigh the cutout for area, then compare its weight against the shoebox it ships in: that ratio is extent, telling flat plates from spindly frames without a single measurement of length.

It stops holding for bent abstractions. Balance and weight cannot tell a boomerang from a banana of equal mass, the same way area and centroid miss concavities. Notches and holes need hull defects and hierarchy, not moments.

How It Actually Works

Moments, centroid, and orientation

The raw moment of order (i,j)(i, j) sums xiyjx^i y^j over the shape: Mij=∑x∑yxiyjI(x,y)M_{ij} = \sum_x \sum_y x^i y^j I(x, y). Area is the zeroth moment M00M_{00}, pure pixel count. The centroid divides first orders by area: xˉ=M10/M00\bar{x} = M_{10} / M_{00}, yˉ=M01/M00\bar{y} = M_{01} / M_{00}. Central moments μij\mu_{ij} subtract the centroid first, making them translation-proof, and the orientation angle comes from the second orders: θ=12tan⁡−1(2μ11/(μ20−μ02))\theta = \frac{1}{2} \tan^{-1}(2\mu_{11} / (\mu_{20} - \mu_{02})).

Verify on a right triangle with vertices (0,0)(0,0), (4,0)(4,0), (0,3)(0,3). Area is 12×4×3=6\frac{1}{2} \times 4 \times 3 = 6, so M00=6M_{00} = 6. The centroid of a triangle averages its vertices: xˉ=4/3≈1.333\bar{x} = 4/3 \approx 1.333, yˉ=1\bar{y} = 1. Hence M10=6×4/3=8M_{10} = 6 \times 4/3 = 8 and M01=6×1=6M_{01} = 6 \times 1 = 6, and both ratios return the centroid exactly.

Perimeter and the ratio descriptors

Perimeter integrates step lengths along the ordered loop, which is why ordering matters. Three ratios then compress shape: aspect ratio (width over height of the upright box), extent (contour area over box area, near 11 for plates), and solidity (contour area over hull area, near 11 for blobs, low for starfish). Filters like "extent above 0.80.8 and solidity above 0.90.9" isolate rectangular chips on a belt with two comparisons.

Code

Shoelace area plus vertex-averaged centroid on the fixture triangle:

verts = [(0, 0), (4, 0), (0, 3)]
area2 = sum(    verts[i][0] * verts[(i + 1) % 3][1] - verts[(i + 1) % 3][0] * verts[i][1]    for i in range(3))area = abs(area2) / 2cx = sum(v[0] for v in verts) / 3cy = sum(v[1] for v in verts) / 3print(f"area {area}, centroid ({cx:.3f}, {cy:.1f})")# -> area 6.0, centroid (1.333, 1.0)

Area 66 and centroid (1.333,1.0)(1.333, 1.0), confirming M10=8M_{10} = 8 and M01=6M_{01} = 6.

Watch Out For

Matching with raw instead of central moments

Symptom: the same part scores as different shapes at different belt positions because M10M_{10} and M01M_{01} grow with absolute pixel coordinates. Raw moments bake position into every value. Translate to central moments μij\mu_{ij}, or normalize further to Hu moments, before any comparison across locations.

Trusting pixelated perimeters absolutely

Symptom: a diagonal edge measures about 40%40\% long because staircase steps count every jog, so circularity scores drift with rotation. Perimeter is resolution- and rotation-sensitive while area is comparatively stable. Compare ratios and ranks rather than absolute perimeters, or smooth and sub-sample the contour first.

The Quick Version

  • M00M_{00} is area; centroid ratios M10/M00M_{10}/M_{00} and M01/M00M_{01}/M_{00} locate the center of mass.
  • Central moments remove translation; second orders yield orientation via the arctangent formula.
  • Extent, solidity, and aspect ratio compress shape into sortable numbers for inspection filters.
  • Perimeter needs the ordered loop and overestimates diagonal edges on pixel grids.
  • Moments miss concavities, so pair them with hull analysis for notched or holed parts.