Image Memory Layout
Storing Images in Memory
A 2D image array must be stored in linear (1D) memory. The mapping from 2D coordinates to 1D memory index uses strides.
Row-Major vs Column-Major Order
Row-Major Order (Most Common)
Elements in the same row are stored contiguously:
Column-Major Order
Elements in the same column are stored contiguously:
Interleaved Colour Storage
For colour images with 3 channels (RGB), interleaved row-major:
where for the R, G, B channels.
General Stride Formula
The most general formula for any memory layout:
where:
- is the starting offset
- , , are the strides for each dimension
Common Stride Configurations
| Layout | |||
|---|---|---|---|
| Row-major, grayscale | 1 | - | |
| Column-major, grayscale | 1 | - | |
| Row-major, interleaved RGB | 3 | 1 | |
| Row-major, planar RGB | 1 |
Padded Images
Sometimes images are padded with extra pixels for operations that need neighbourhood access (e.g., convolution).
The stride is larger than the image width to account for padding.
Regions of Interest (ROI)
A region of interest is a rectangular subset of an image. An ROI borrows the parent’s data array without copying:
- = offset to ROI origin
- Strides are inherited from parent
Summary
- Row-major order stores rows contiguously; column-major stores columns contiguously
- Strides define the step size for each dimension
- Interleaved RGB alternates channels; planar separates them
- ROIs share parent memory without copying
Past Paper Questions
2023 Paper 3 Question 4: Design an ExImage class that supports ROIs. What constructor parameters are needed?