Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 1.15 KB

File metadata and controls

26 lines (21 loc) · 1.15 KB
  1. Planar (Channel-First, e.g., RRR...GGG...BBB...) All pixels for one channel are stored together. Example for a 2x2 RGB image: [R0, R1, R2, R3, G0, G1, G2, G3, B0, B1, B2, B3] Access pattern: image[channel][row][col] or image[c][h][w] Common in some frameworks (e.g., PyTorch: NCHW).
  2. Interleaved (Channel-Last, e.g., RGBRGB...) Each pixel’s channels are stored together. Example for a 2x2 RGB image: [R0, G0, B0, R1, G1, B1, R2, G2, B2, R3, G3, B3] Access pattern: image[row][col][channel] or image[h][w][c] Common in image files, OpenCV, and some frameworks (e.g., TensorFlow: NHWC).

How does this affect Conv2D and your code? Indexing:

If your data is planar, you must calculate indices differently than if it’s interleaved. For planar: index = c * H * W + h * W + w For interleaved: index = h * W * C + w * C + c Performance:

Interleaved is often more cache-friendly for per-pixel operations. Planar can be more efficient for vectorized operations per channel. Correctness:

If your Conv2D expects interleaved but you provide planar, the output will be incorrect (colors/features will be mixed up). Always ensure your data format matches what your code expects.