A robot vision program can obtain a rectangular pixel sum from four table entries after building an image prefix table. The arithmetic is compact, but the entries only make sense when the table's coordinate and endpoint conventions are explicit.

One library can store an extra zero border and exclude the indicated endpoint. Another can include the indicated pixel and keep the original image shape. The same pixels can be queried under either convention, but their table indices differ.

The original array below makes the translation visible. It is a numerical construction rather than a camera image, a library execution, or a measured processing benchmark.

Define the source image and its coordinates

Use four columns with x indices zero through three and three rows with y indices zero through two. The pixel value at column x and row y is I(x, y).

The rows are:

y = 0: [2, 1, 3, 0].

y = 1: [4, 2, 1, 5].

y = 2: [0, 3, 2, 1].

The values are dimensionless invented grayscale codes. They are not assumed to represent calibrated light intensity or a physical area.

Define a padded prefix table S(X, Y) as the sum of source pixels with x < X and y < Y. The table has five columns and four rows, including S(0, Y) = 0 and S(X, 0) = 0.

OpenCV's integral reference documents this exclusive-endpoint, added-border convention. Scikit-image's integral_image reference documents a different inclusive prefix. Their contracts supply the indexing distinction; the values below are independently calculated.

Build the padded table

Each entry can be obtained from its upper and left prefixes plus the current source value, subtracting the overlap counted twice. In the present notation:

S(X, Y) = I(X − 1, Y − 1) + S(X − 1, Y) + S(X, Y − 1) − S(X − 1, Y − 1), for positive X and Y.

The complete table rows, listed in increasing Y, are:

Y = 0: [0, 0, 0, 0, 0].

Y = 1: [0, 2, 3, 6, 6].

Y = 2: [0, 6, 9, 13, 18].

Y = 3: [0, 6, 12, 18, 24].

For example, S(3, 2) sums the first three columns of the first two source rows: 2 + 1 + 3 + 4 + 2 + 1 = 13. S(4, 3) sums all twelve source pixels and equals 24.

The zero border represents empty prefixes. It is not an additional row or column of measured image data.

Recover one rectangle with four entries

Select columns satisfying 1 <= x < 4 and rows satisfying 1 <= y < 3. This rectangle contains three columns and two rows, with six selected values: [2, 1, 5] and [3, 2, 1].

Starting from S(4, 3) includes the wanted rectangle plus unwanted prefixes above and to its left. Subtract S(1, 3) to remove the left prefix, and subtract S(4, 1) to remove the top prefix.

The top-left overlap was removed twice, so add S(1, 1) back. The result is 24 − 6 − 6 + 2 = 14, matching the direct six-value sum.

In general, the rectangle [x1, x2) by [y1, y2) has sum S(x2, y2) − S(x1, y2) − S(x2, y1) + S(x1, y1).

The plus sign on the final term follows inclusion-exclusion. Dropping it in this example would produce twelve rather than fourteen.

Mean needs the rectangle's sample count

The selected count is (4 − 1)(3 − 1) = 6. Its mean is 14/6 = 7/3, approximately 2.333333.

The four prefix entries are not four observations to average. They summarize overlapping sets of different sizes. Dividing their combined sum by four would attach the wrong denominator to the selected image region.

An empty rectangle can have zero sum but no defined sample mean. For example, x1 = x2 yields no selected columns. Its zero count cannot be used as an ordinary division denominator.

The four-corner formula also assumes bounds within the represented image. Clipping a requested rectangle changes both its selected pixels and its count; a prefix table does not choose that boundary policy automatically.

Translate to an inclusive prefix convention

Define T(x, y) as the sum over source indices i <= x and j <= y. Its shape is the original four columns by three rows. For valid source indices, T(x, y) = S(x + 1, y + 1).

The same selected pixels now have inclusive endpoints x = 1 through 3 and y = 1 through 2. Their sum is T(3, 2) − T(0, 2) − T(3, 0) + T(0, 0).

Those values are again 24, 6, 6, and 2. The result remains fourteen. The index translation changed the table addresses while preserving the selected region.

A rectangle touching the first source row or column needs the empty-prefix case handled explicitly in this inclusive form. Reading an array at a negative index is not automatically equivalent to the required mathematical zero prefix.

Separate a query count from a performance claim

After the table exists, an axis-aligned rectangle sum uses a fixed number of prefix accesses, independent of the rectangle's pixel count. Building and storing the table still requires work and memory related to the whole image.

Accumulation precision also belongs in the record. A prefix can sum many more values than one pixel contains, so a pixel storage type is not automatically an adequate sum type. No timing or capacity guarantee follows from this small array.

For robot image records, preserve the coordinate order, endpoint convention, region bounds, accumulator type, and count used by any mean. The original rectangle then has one reproducible sum even when two APIs address its prefixes differently.

Sources checked October 23, 2026

OpenCV 4.13.0, Miscellaneous Image Transformations, integral:

https://docs.opencv.org/4.13.0/d7/d1b/group__imgproc__misc.html

Scikit-image 0.25.2, transform.integral_image and integrate:

https://scikit-image.org/docs/0.25.x/api/skimage.transform.html

All arrays and queries are original hypothetical calculations. No image-processing library was executed.

Illustration note: A generic robot vision scene is a concept illustration. It does not show the constructed array or a measured image-processing result.