A robot camera image has five columns and three one-byte channels. Fifteen bytes describe the active pixels in one row. That does not establish that the next row begins fifteen bytes later.

An image buffer can leave additional bytes between rows. A cropped image view can preserve an even larger gap because it still refers to storage belonging to its parent image. Treating every image as one tightly packed sequence can consequently select the wrong pixels without changing the declared width or channel count.

The following addresses belong to invented buffers. They illustrate layout arithmetic, not the execution of a vision library or a camera test.

Define the byte layout before indexing

Assume an interleaved image in which each pixel has three channels, each stored in one byte. Channel order is fixed but need not be named for this calculation. Exclude packed sub-byte formats, planar channels, compression, and negative strides.

Let W be the number of columns, H the number of rows, and S the byte distance between the beginnings of successive rows. Number rows y and columns x from zero. Number channels c from zero through two.

Relative to the start of the first row, a channel's byte offset is:

offset(y, x, c) = yS + 3x + c.

The active bytes per row are 3W. The quantity S describes row spacing. They are equal only when this layout has no extra spacing between rows.

ROS 2's rolling sensor_msgs Image definition calls step the full row length in bytes and defines its data size as step times rows. OpenCV 4.12.0 documents matrix addresses using step and explains that a supplied row step includes end-of-row padding. These definitions establish the accounting distinction.

One padding byte changes later row addresses

Choose W = 5, H = 3, and S = 16 bytes. Each row has fifteen active bytes followed by one padding byte.

Row zero's active offsets are 0 through 14, with padding at 15. Row one starts at 16, uses offsets 16 through 30, and has padding at 31. Row two starts at 32, uses 32 through 46, and has padding at 47.

The active pixel count occupies 45 bytes. The declared full three-row buffer occupies 48 bytes, including three padding bytes.

The final channel of pixel (x = 4, y = 2) is at offset 2 × 16 + 3 × 4 + 2 = 46. Substituting 15 for the actual stride would calculate 44 instead.

That two-byte difference comes from missing one padding byte at each preceding row boundary. It is an address error, rather than a change in sensor brightness resolution.

Padding does not represent another column

The byte at offset 15 is outside the first row's five pixels. Its value does not define an additional pixel or an extra channel of the last pixel.

If a consumer reads fifteen bytes as the first row and immediately continues with the next fifteen, its supposed second row starts at the first row's padding. Its channel grouping then shifts relative to the intended image.

One plausible-looking first row therefore does not establish that the complete image layout was interpreted correctly. A row-address calculation needs to remain valid at every boundary.

A cropped view changes the origin, not necessarily the stride

Keep the same parent buffer. Select a two-column, two-row region beginning at parent column 1, row 1.

The first selected byte is at parent offset 16 + 3 = 19. The first selected row contains offsets 19 through 24. The next selected row contains offsets 35 through 40.

Measured from the cropped view's origin, those active intervals are 0 through 5 and 16 through 21. Its active row length is six bytes, but its inherited row stride remains sixteen.

The ten-byte gap between selected rows includes parent-image pixels outside the region and a parent padding byte. It is not necessarily ten bytes originally allocated as row padding.

OpenCV's documentation describes submatrix headers sharing parent data and notes that extracted regions need not be continuous. The example demonstrates why a smaller logical rectangle does not by itself imply a compact physical layout.

A flat copy can select the wrong region

The crop contains twelve active bytes. Reading twelve consecutive bytes starting at parent offset 19 would take offsets 19 through 30.

The first six are the selected first row. The next six belong to other columns of that same parent row, rather than the crop's second row at offsets 35 through 40.

The byte count is correct for a compact crop, but the selected byte locations are wrong. Correct size arithmetic cannot replace correct stride arithmetic.

A hypothetical compact representation would place the two selected six-byte rows next to each other in a new twelve-byte buffer, with row stride six. That operation changes storage layout while preserving the selected pixel values.

A view is not already a serialized image message

The parent allocation in this example contains offsets 0 through 47. The cropped view's active pixels remain within it, ending at offset 40.

Nevertheless, interpreting its origin at 19 as the beginning of a separate two-row ROS image buffer with step sixteen would require thirty-two bytes, through parent offset 50. The parent allocation does not contain that complete interval.

This difference matters because a view's valid selected pixels and a message's declared contiguous data extent are separate contracts. An inherited pointer and stride cannot simply be relabeled as a complete serialized crop without accounting for those contracts.

The illustration does not specify a particular library's serializer. It shows why buffer extent must accompany the logical view dimensions.

Keep representation and pixel meaning separate

All channels here use one byte, so byte order within a multibyte channel is irrelevant to the example. Other encodings need their own element sizes and channel layout. A general packed or planar format should not be forced into the displayed three-byte formula.

For this declared interleaved layout, the useful record includes dimensions, encoding, first-row origin, stride, and accessible storage extent. A compact copy and a shared crop can represent the same pixels while requiring different row addresses.

The practical result is precise: width describes how many pixels belong to a row; stride describes where the next row begins. Keeping both quantities makes row padding and cropped views interpretable without mistaking extra storage bytes for image information.

Sources checked October 23, 2026

ROS 2 common_interfaces, rolling sensor_msgs Image.msg, mutable branch source as accessed:

https://raw.githubusercontent.com/ros2/common_interfaces/rolling/sensor_msgs/msg/Image.msg

OpenCV 4.12.0, cv::Mat class reference, step addressing, supplied-data constructors, submatrix headers, and isContinuous:

https://docs.opencv.org/4.12.0/d3/d63/classcv_1_1Mat.html

All dimensions, offsets, and buffers are original hypothetical examples. No camera acquisition or library execution is claimed.

Illustration note: An accompanying generic robot-camera or computer-vision scene is a concept illustration. It does not show the invented memory layout or a measured buffer-transfer result.