AI Glossary / Computer vision and multimodal AI / Advanced

Interleaved (HWC) layout

Definition

An interleaved HWC image layout organizes data by height, width and channel, with channel values grouped for each pixel in a conventional contiguous representation. For an RGB image, this commonly places one pixel's three channel values together before the next pixel's values. HWC describes axis order; actual physical storage also depends on strides and contiguity.

What it means

The same image values can be arranged in different orders without changing what the picture represents. HWC emphasizes pixels with their channels together, while CHW places the channel axis first and is commonly associated with separate channel planes in contiguous storage. Neither label specifies whether the channels are RGB or BGR, whether values are integers or floating point, or how they are scaled. Those details must be supplied independently. Adding a batch axis gives conventions such as NHWC, where N indexes images.

How it works

For a contiguous row-major HWC array with width W and C channels, the element at row y, column x and channel c has element offset (yW+x)C+c. Byte offsets additionally depend on element size. Padded rows and non-contiguous views require explicit strides instead of this simplified formula. Converting axis order generally requires a transpose or permutation; a plain reshape does not necessarily rearrange values into the intended correspondence. Libraries may distinguish logical tensor dimensions from physical memory format, so both must be understood when exchanging arrays.

Three practical examples

  • A camera-processing pipeline passes a color image to a model and checks whether the receiving operation expects channels first or channels last.
  • A developer creates a tiny image with distinctive channel values to verify that a layout conversion preserves pixel identity and channel meaning.
  • An imaging application handles a cropped array view and uses its actual strides rather than assuming every row is tightly packed.

Think of it this way

Imagine filing cards for two customers, each with three contact fields. One arrangement keeps each customer's fields together; another keeps all phone numbers together, then all email addresses, then all postal addresses. The information can be identical, but a reader must know the arrangement. HWC and CHW express a comparable ordering choice for image data. The analogy also shows why changing labels on the drawers is insufficient if the cards themselves are not rearranged consistently.

Worked example

In an original one-row, two-pixel RGB image, pixel zero has values (10,20,30) and pixel one has values (40,50,60). A contiguous HWC sequence is [10,20,30,40,50,60]. A contiguous CHW sequence for the same image is [10,40,20,50,30,60], grouping each channel's two spatial values. In HWC, the second pixel's green component has offset (0×2+1)×3+1=4 and value 50. Simply reshaping the original sequence into three rows would not produce the stated CHW sequence. This example uses one-byte-independent element indexing and does not assume that channel order or data type changes with the layout.

Illustrative case study

A fictional retail-vision team moves image preprocessing between two libraries. The output has the expected total number of values, but predictions deteriorate because the conversion reshaped the array instead of permuting its axes. The team tests a small image with uniquely numbered components and corrects the correspondence. It separately checks channel order and normalization. This scenario illustrates why matching array size is not enough. It does not claim that every model expects a particular layout or that one arrangement is universally faster across hardware and operations.

Common misconceptions and mistakes

HWC does not mean RGB, and CHW does not mean BGR. Axis layout and channel semantics are independent. Another mistake is assuming every HWC-shaped object is contiguous; array views can carry different strides. A reshape and a transpose have different meanings, even when both change reported dimensions. Layout conversion should also not silently change numeric scaling. Finally, performance depends on the implementation and workload. Claims that one layout is always best ignore backend-specific memory formats, supported operations and conversion overhead.

Business use

Layout errors can silently undermine image pipelines while leaving files readable and tensor sizes plausible. Teams should document axis order, channel meaning, data type, scaling and stride assumptions at system boundaries. Test conversions using known values rather than relying only on a visual preview. Measure performance on the actual deployment path, including conversion costs. A clear input contract helps prevent a model-quality investigation from being misdirected when the real issue is an incorrectly interpreted array. Preserve those contracts when updating libraries or exporting models.

People also ask

Does HWC identify the color space?

No. It identifies axis order, while color interpretation requires separate metadata or conventions.

Is NHWC different from HWC?

NHWC includes a leading batch axis in addition to height, width and channels.

Can reshape replace a channel-axis permutation?

Not generally. Reinterpreting dimensions alone does not necessarily put values in the required order.

Check your understanding

Where was the second pixel's green value in the contiguous HWC example?

Answer: At element offset 4.

Why did the CHW sequence differ?

Answer: It grouped spatial values by channel.

What should replace the simple offset formula for a padded or non-contiguous array?

Answer: Its actual strides and element-size information.

Related terms

  • Transpose
  • CHW
  • NHWC
  • tensor stride
  • contiguous array
  • channel order

Learn next

Build a two-pixel array with unique channel values and convert between HWC and CHW. Verify every component after converting back. Then inspect a cropped or transposed view to see how logical shape and physical strides can differ.

More in Computer vision and multimodal AI

  • Impulse (delta) - An impulse, or delta, is an idealized localized input used in signal and image processing.
  • Integral image - An integral image, also called a summed-area table, stores cumulative sums of image values so that sums over axis-aligned rectangular regions can be...
  • Intelligent scissors (live-wire) - Intelligent scissors, also called live-wire in related interactive boundary-selection workflows, helps a user trace an image boundary by finding low-cost...
  • Intermediate representation - An intermediate representation, or IR, is a structured form of a program or computation used between stages of translation, analysis or optimization.
  • Interval tree - An interval tree is a data structure for storing ranges and efficiently finding ranges that overlap a query interval or contain a query point.
  • Intrinsic-image decomposition - Intrinsic-image decomposition estimates separate components of an image that describe properties such as surface reflectance and shading.

Sources

TensorFlow, space_to_depth, data-format definitions: https://www.tensorflow.org/api_docs/python/tf/compat/v1/nn/space_to_depth The two-pixel calculation, filing-card analogy and retail-vision case are original educational illustrations. The offset formula assumes contiguous row-major storage; real array interfaces may expose additional stride and memory-format conventions.

Previous: Interlaced video Next: Interleaving

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer