A binary inspection mask contains fifteen foreground pixels. A polygon drawn through its outer pixel centers can have area eight. Both results can follow correctly from the same small rectangular arrangement because they measure different geometric representations.

The distinction matters when a robot vision report labels either value simply as area. A count assigns membership to image samples. A polygon calculation assigns a continuous region to a boundary. The meaning of a threshold depends on which representation generated it.

The examples below are original masks and explicitly declared polygons. They are not outputs from an executed contour extractor or measurements of a physical part.

Give each foreground sample a cell

Use integer image coordinates (x, y) for pixel centers. For this construction, associate each pixel with a unit square extending half a coordinate unit in every direction from its center. Adjacent squares meet along edges without overlapping interiors.

Fill five columns with center coordinates x = 0, 1, 2, 3, 4 and three rows with y = 0, 1, 2. Every sample in that block is foreground, and surrounding samples are background.

There are 5 times 3 = 15 foreground samples. If each selected sample represents its unit square, their union has area 15 square coordinate units. Its outer edges lie at x = −0.5 and 4.5, and y = −0.5 and 2.5.

That outer rectangle therefore has width five and height three. The count and the union area agree because the unit-cell interpretation was explicitly chosen.

Now construct a center polygon

Use the four outer corner centers as the vertices of a separate polygon: (0, 0), (4, 0), (4, 2), and (0, 2), in that order. Its width is four and its height is two, giving area eight.

The polygon passes through centers of boundary pixels. It does not run around the exterior edges of their unit squares. Consequently, it represents a smaller continuous region than the cell union.

For a simple polygon with cyclic vertices, the absolute shoelace area is one-half the absolute value of the sum of x_i y_(i+1) minus y_i x_(i+1). Applying it to these four vertices gives one-half of 16, or eight.

OpenCV's contourArea documentation describes a Green-formula polygon area and explicitly notes that it can differ from a rasterized nonzero-pixel count. Its countNonZero documentation defines a count of nonzero elements in a single-channel array. Those are different contracts. The construction here explains the geometry without claiming a particular contour-retrieval setting returns these four vertices.

A general rectangular discrepancy

For a full rectangular block with w columns and h rows of unit-spaced centers, the pixel-cell area is wh. The rectangle through its four extreme centers has area (w − 1)(h − 1).

Subtracting gives a discrepancy of w + h − 1 square coordinate units. For w = 5 and h = 3, that is seven, matching 15 minus eight.

This formula applies to the declared rectangular construction. It is not a universal correction to add to the area of every contour. Irregular boundaries, holes, approximate vertices, and other sampling conventions require their own geometry.

Translating the rectangle does not change either result. Rescaling all coordinates multiplies both continuous areas by the square of the scale, while the number of stored foreground samples stays fifteen. A coordinate transformation and a change in sample membership are separate operations.

Thin regions expose the difference

Consider a single foreground pixel. Its assigned unit square has area one. A boundary represented solely by that pixel's center is a point, with zero continuous polygon area.

For a row of five foreground pixels, the union of unit cells has area five. A path through only the row's centers lies on one straight line, so closing that center path does not enclose a positive area.

Thus a positive foreground count can coexist with a zero area for a degenerate center polygon. Deleting the region because a polygon-area rule returns zero would apply a geometric criterion different from retaining a fixed number of foreground samples.

Neither representation is automatically the correct one for every inspection question. A region-size gate based on occupied image samples needs the counting definition. An area of a declared continuous boundary needs that boundary's geometry.

Holes require an explicit region rule

Return to the fifteen-pixel rectangle and change only its central sample, at (2, 1), to background. The foreground count falls to fourteen. Under the unit-cell interpretation, the union has a one-unit-square hole, so its net area is fourteen.

The four extreme foreground centers remain unchanged. The same outer center rectangle still has area eight. Calculating that outer polygon alone says nothing about whether an interior hole should be removed.

One can instead describe the unit-cell union by an exterior boundary of area fifteen and an interior square boundary of area one, then subtract to obtain fourteen. That is an explicitly different boundary representation from the outer-center polygon.

A collection of contour vertices therefore needs a hierarchy or a declared combination rule when holes matter. Summing absolute areas without identifying exterior and interior regions can count an interior boundary in the wrong direction. The arithmetic must follow the intended region semantics.

Physical units require more than a label

Suppose an invented planar mapping assigns 0.2 millimeter to each coordinate unit in both directions. Each unit square then represents 0.04 square millimeter. The full fifteen-cell union maps to 0.6 square millimeter, while the eight-unit center polygon maps to 0.32 square millimeter.

Multiplying by the same scale does not reconcile their definitions. It preserves their disagreement. With the central cell removed, the unit-cell result becomes 0.56 square millimeter.

These numbers assume the stated uniform planar scale. Perspective, distortion, variable depth, and segmentation uncertainty can invalidate a simple constant-area mapping. Even an exact count of foreground cells does not establish the true physical outline of a part.

An interpretable mask-area record names the foreground rule, pixel-coordinate convention, region representation, treatment of holes, and any physical mapping. The small rectangle then becomes easy to explain: fifteen counts selected cells; eight measures the separate polygon through selected centers.

Sources checked October 23, 2026

OpenCV 4.12.0, Operations on Arrays, countNonZero:

https://docs.opencv.org/4.12.0/d2/de8/group__core__array.html

OpenCV 4.13.0, Structural Analysis and Shape Descriptors, contourArea:

https://docs.opencv.org/4.13.0/d3/dc0/group__imgproc__shape.html

All masks, vertices, and area calculations are original hypothetical constructions. No OpenCV functions were executed.

Illustration note: The accompanying site-library robot vision scene is a concept illustration. It does not show the constructed binary masks, a measured contour, or a verified part area.