Mix channels is a copy operation from a set of input channels to a set of output channels. The set of inputs and outputs may be given by any number of input and output images, where each image may have one or more channels.
The channel mapping from input to output is given by two arrays, one with the indices of the input channels, and the another with the corresponding channel index in the output.
The channel indices are enumerated starting from zero and increasing monotonically across all channels of all images provided in the array. For example, given an array of 3 RGB images, index 5 corresponds to the B channel of the second image.
The following table shows two examples of mix channels usage. The left one extracts each channel of an RGB image into three RGB images, in the correspondent red, green and blue channels. Remaining channels are unchanged.
The algorithm is implemented as a pixel-wise copy function that reads in each input channel and writes it to the corresponding output channel. The algorithm expects the sizes of the input and output image planes to match, that is, it will not do chroma up/downsampling for instance. Furthermore, the algorithm will not do any color or pixel range conversions between input and output formats. It'll do, however, conversions between integer and floating-point values. Underflows and overflows are handled as per C language rules for such casts. For image format conversion (including proper color conversion), refer to Convert Image Format.
All input and output images must be allocated before calling the mix channels operation.
The following figure shows some examples of channel mixing possible. Each blue box represents one channel, and grouped boxes represent an image. Numbers inside the channel box represent the channel index with respect to the image, and numbers outside the boxes represent the corresponding channel index to be used in the channel mapping array. Note that the same input channel can be copied to several output channels, and output channels that aren't written to keep their original content.
C API functions
For list of limitations, constraints and backends that implements the algorithm, consult reference documentation of the following functions:
Create the output image list from an input image, all images have same dimensions and format as input. It's assumed that input's format is vpi.Format.RGB8.
Runs the mix channels algorithm. Each one of input channels (RGB) are mapped to its corresponding channels in the 3 output images, i.e., first image R channel receives input's R channel, second image G channel receives input's G channel, etc. The other output channels aren't touched, and keep their original content, in this case, all zeros. The result is 3 color images showing the red, green and blue channels of the input image.
Initialize the input and output mapping arrays so that each one of input channels (RGB) are mapped to its corresponding channels in the 3 output images, i.e., first image R channel receives input's R channel, second image G channel receives input's G channel, etc. The other output channels aren't touched, and keep their original content, in this case, all zeros. The result is 3 color images showing the red, green and blue channels of the input image.
int mappingIn[3] = {0, 1, 2};
int mappingOut[3] = {0, 4, 8};
Submit the algorithm and its parameters to the stream. It'll be executed by the CPU backend. In this example, there is one input image, three output images and a mapping for 3 channels.
VPIStatus vpiSubmitMixChannels(VPIStream stream, uint64_t backend, VPIImage *inputs, int numInputs, VPIImage *outputs, int numOutputs, const int *inMapping, const int *outMapping, int numMapping)