Jump to content

ReformatOp

From RidgeRun Developer Wiki

🚧 Documentation is under development

The Holoscan SDK guide is currently under active development. Some sections may be incomplete or change without notice.

Questions? Contact RidgeRun or email to support@ridgerun.com.

Contents Pin





ReformatOp

ReformatOp converts CUDA image storage between interleaved HWC/NHWC and planar CHW/NCHW layouts. It produces a new contiguous tensor with the same image dimensions, channel count, scalar type, and capture metadata.

Layout describes where the channel values are stored. A BGR image remains BGR; changing the layout does not swap channels, normalize values, or convert the numeric type.

Input arguments

ReformatOpParams has one field, mode, defaulting to kInterleavedToPlanar. Its ReformatMode choices are:

Mode Shape Transformation
kInterleavedToPlanar [H,W,C] → [C,H,W]; [N,H,W,C] → [N,C,H,W].
kPlanarToInterleaved [C,H,W] → [H,W,C]; [N,C,H,W] → [N,H,W,C].

The field is CompileTime, frozen for one accepted plan. Configure it before compilation and compile a new plan to change direction. It is not marked as an admitted runtime-mutable field. Output capacity follows the connected input's finite byte bound. The operator has no separate image-capacity constructor.

Ports and data contract

Port Memory Queue Trigger Contract
input CUDA device 1 OnEach Rank-three or rank-four image using a supported scalar type and the configured interleaved or planar layout.
output CUDA device N/A Same activation Same image data in the requested layout. Capture metadata is preserved.

The layout and direction are configured explicitly. Interleaved channels and planar pixels must be packed as required by the selected layout.

Example

With graph already declared and <holoscan/vision/reformat_op.hpp> included:

auto reformat = graph.op<holoscan::vision::ReformatOp>("to-planar");
reformat.set_params(holoscan::vision::ReformatOpParams{
    .mode = holoscan::vision::ReformatMode::kInterleavedToPlanar,
});

An HWC [2,2,3] result becomes CHW [3,2,2]. The first output plane contains the first channel's four pixels, then the second and third planes follow. Connect the interleaved CUDA result to reformat->input; its output is suitable only for a consumer that accepts the resulting planar representation.

For the reverse direction, set kPlanarToInterleaved and supply CHW/NCHW input. Reformat changes storage order through GPU work; it is not a metadata-only view.

Build

Follow Build the SDK on AGX Orin for the SDK build and installation. Link the installed holoscan::vision target in the application.


Related examples and concepts

Examples

Concepts

Source You can find the source code at ReformatOp.

Official documentation

NVIDIA Holoscan SDK User Guide provides the official operator and application reference.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.