CropFlipNormalizeReformat

group NVCV_C_ALGORITHM_CROP_FLIP_NORMALIZE_REFORMAT

Functions

NVCVStatus cvcudaCropFlipNormalizeReformatCreate(NVCVOperatorHandle *handle)

Constructs and an instance of the SliceFlipNormalize operator.

Parameters:

handle[out] Where the image instance handle will be written to.

  • Must not be NULL.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – Handle is null.

  • NVCV_ERROR_OUT_OF_MEMORY – Not enough memory to create the operator.

  • NVCV_SUCCESS – Operation executed successfully.

NVCVStatus cvcudaCropFlipNormalizeReformatSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVImageBatchHandle in, NVCVTensorHandle out, NVCVTensorHandle cropRect, NVCVBorderType borderMode, float borderValue, NVCVTensorHandle flipCode, NVCVTensorHandle base, NVCVTensorHandle scale, float global_scale, float shift, float epsilon, uint32_t flags)

Executes the CropFlipNormalizeReformat operation on the given cuda stream. This operation does not wait for completion.

This operation performs the following steps:

  1. Pad and Crop the input image to the specified rectangle.

  2. Flip the cropped image horizontally and/or vertically.

  3. Normalize the flipped image using the provided base and scale.

  4. Convert the normalized image to the specified output data type.

  5. Reformat the normalized image to the specified output layout.

Data normalization is done using externally provided base (typically: mean or min) and scale (typically reciprocal of standard deviation or 1/(max-min)). The normalization follows the formula:

out[data_idx] = (in[data_idx] - base[param_idx]) * scale[param_idx] * global_scale + shift
Where data_idx is a position in the data tensor (in, out) and param_idx is a position in the base and scale tensors (see below for details). The two additional constants, global_scale and shift can be used to adjust the result to the dynamic range and resolution of the output type.

The scale parameter may also be interpreted as standard deviation - in that case, its reciprocal is used and optionally, a regularizing term is added to the variance.

m = 1 / sqrt(square(stddev[param_idx]) + epsilon)
out[data_idx] = (in[data_idx] - mean[param_idx]) * m * global_scale + shift

param_idx is calculated as follows (where axis = N,H,W,C):

param_idx[axis] = param_shape[axis] == 1 ? 0 : data_idx[axis]

For the Crop operation, the input image is cropped to the specified rectangle. The rectangle is [crop_x, crop_y, crop_x + crop_width, crop_y + crop_height]. Where the crop_x and crop_y can be negative, in which case the image is padded. The padding method is specified by the borderMode parameter.

Limitations:

Input: Data Layout: [kNHWC, kHWC, kNCHW, KCHW] Channels: [1, 3, 4]

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

Yes

16bit Unsigned

Yes

16bit Signed

Yes

32bit Unsigned

Yes

32bit Signed

Yes

32bit Float

Yes

64bit Float

No

Output: Data Layout: [kNHWC, kHWC, kNCHW, KCHW] Channels: [1, 3, 4]

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

Yes

16bit Unsigned

Yes

16bit Signed

Yes

32bit Unsigned

Yes

32bit Signed

Yes

32bit Float

Yes

64bit Float

No

Input/Output dependency

 Property      |  Input == Output
-------------- | -------------
 Data Layout   | Yes/No
 Data Type     | Yes/No
 Number        | Yes
 Channels      | Yes
 Width         | Yes/No
 Height        | Yes/No

Parameters:
  • handle[in] Handle to the operator.

    • Must not be NULL.

  • stream[in] Handle to a valid CUDA stream.

  • in[in] Input image batch.

  • out[out] Output tensor.

  • cropRect[in] crop rectangle tensor which has shape of [batch_size, 1, 1, 4] in reference to the input tensor. The crop value of [crop_x, crop_y, crop_width, crop_height] stored in the final dimension of the crop tensor

  • borderMode[in] Border mode to be used when accessing elements outside input image, cf. NVCVBorderType.

  • borderValue[in] Border value to be used for constant border mode NVCV_BORDER_CONSTANT.

  • flipCode[in] a tensor flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.

  • base[in] Tensor providing base values for normalization.

  • scale[in] Tensor providing scale values for normalization.

  • global_scale[in] Additional scale value to be used in addition to scale.

  • shift[in] Additional bias value to be used in addition to base.

  • epsilon[in] Epsilon to use when CVCUDA_NORMALIZE_SCALE_IS_STDDEV flag is set as a regularizing term to be added to variance.

  • flags[in] Algorithm flags, use CVCUDA_NORMALIZE_SCALE_IS_STDDEV if scale passed as argument is standard deviation instead or 0 if it is scaling.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – Some parameter is outside valid range.

  • NVCV_ERROR_INTERNAL – Internal error in the operator, invalid types passed in.

  • NVCV_SUCCESS – Operation executed successfully.