Table of Contents

Enum DataLayout

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Data layout of a matrix / tensor (OpenCV 5, cv::DataLayout). Defined in the core module and shared by core (MatShape) and dnn (e.g. blob-from-image parameters).

public enum DataLayout

Fields

BLOCK = 7

Block layout (also written "NC1HWC0"), where channels are split into blocks. Some hardware accelerators require it, and it can also be faster on CPU. This is the layout for which Channels (C) is meaningful.

NCDHW = 3

Channel-first 5-D layout for volumetric (3-D) data: batch, channels, depth, height, width (N, C, D, H, W).

NCHW = 2

Channel-first 4-D layout: batch, channels, height, width (N, C, H, W). This is the OpenCV / Caffe / PyTorch / ONNX default for image batches.

ND = 1

Generic OpenCV layout for plain N-dimensional data (typically 2-D matrices) with no special channel ordering.

NDHWC = 5

Channel-last 5-D layout for volumetric (3-D) data: batch, depth, height, width, channels (N, D, H, W, C). TensorFlow-style.

NHWC = 4

Channel-last 4-D layout: batch, height, width, channels (N, H, W, C). This is the TensorFlow-style ordering for image batches.

PLANAR = 6

TensorFlow-like planar layout. Intended only for TensorFlow / TFLite model parsing.

UNKNOWN = 0

Unknown / unspecified layout.

Remarks

The names describe the order of the tensor axes, where each letter is one axis:

  • N — batch size (number of samples)
  • C — channels (e.g. 3 for RGB, or feature-map count)
  • D — depth (the extra spatial axis of volumetric / 3D data)
  • H — height (rows)
  • W — width (columns)

So "NCHW" means the data is ordered batch → channels → height → width (channel-first), while "NHWC" puts the channels last (channel-last). The order only changes how the same pixels are laid out in memory; it does not change the image itself.