Adjust Contrast

group Adjust Contrast

Functions

NVCVStatus cvcudaAdjustContrastCreate(NVCVOperatorHandle *handle)

Constructs an instance of the AdjustContrast 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 cvcudaAdjustContrastSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out, double contrastFactor)

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

Blends each image toward its grayscale mean by a single scalar factor, matching torchvision.transforms.v2.functional.adjust_contrast:

  out = clamp(contrastFactor * in + (1 - contrastFactor) * mean, 0, bound)

where bound is 1.0 for floating-point images and the dtype maximum for integer images, and mean is the per-image mean of its grayscale conversion. Grayscale uses the BT.601 luma weights 0.2989 R + 0.587 G + 0.114 B (floored for integer 3-channel input, matching torchvision); a single-channel image is its own grayscale. A factor of 0 produces a flat gray image, 1 leaves the image unchanged, and values > 1 increase contrast. Integer results round-to-nearest, so they may differ from torchvision (which truncates) by at most 1 LSB. Three-channel tensors are interpreted in RGB component order. Three-channel image batches use their RGB format semantics; formats without a color model are interpreted as RGB. The format swizzle is honored, including BGR storage order.

Reference: torchvision.transforms.v2.functional.adjust_contrast (out = clamp(factor * in + (1 - factor) * grayscale_mean, 0, bound)).

Limitations:

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

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

No

16bit Unsigned

No

16bit Signed

No

32bit Unsigned

No

32bit Signed

No

16bit Float

No

32bit Float

Yes

64bit Float

No

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

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

No

16bit Unsigned

No

16bit Signed

No

32bit Unsigned

No

32bit Signed

No

16bit Float

No

32bit Float

Yes

64bit Float

No

Input/Output dependency

Property

Input == Out

Data Layout

Yes

Data Type

Yes

Channels

Yes

Width

Yes

Height

Yes

Samples

Yes

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

    • Must not be NULL.

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

  • in[in] Input tensor to get values from.

    • Must not be NULL.

  • out[out] Output tensor to set values to.

    • Must not be NULL.

  • contrastFactor[in] Non-negative scalar contrast multiplier.

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.

NVCVStatus cvcudaAdjustContrastVarShapeSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVImageBatchHandle in, NVCVImageBatchHandle out, double contrastFactor)

Executes the AdjustContrast operation on a batch of images.

Apart from input and output image batches, all parameters are the same as cvcudaAdjustContrastSubmit.

Parameters:
  • in[in] Input image batch.

  • out[out] Output image batch.