Jpeg Compression Distortion
- group Jpeg Compression Distortion
Functions
-
NVCVStatus cvcudaJpegCompressionDistortionCreate(NVCVOperatorHandle *handle)
Constructs an instance of the JpegCompressionDistortion operator.
- Parameters:
handle – [out] Where the operator 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 cvcudaJpegCompressionDistortionSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out, NVCVTensorHandle quality)
Executes the JpegCompressionDistortion operation on the given cuda stream. This operation does not wait for completion.
JpegCompressionDistortion simulates the artifacts of a JPEG compression/decompression round trip: 3-channel RGB images are converted to full-range JFIF YCbCr, chroma is 4:2:0 subsampled (2x2 box average on RGB, nearest-neighbor upsampling on reconstruction), and every 8x8 block of each plane goes through a DCT, quantization with the JPEG Annex-K tables scaled by the libjpeg quality mapping, dequantization and inverse DCT. 1-channel images are treated as a bare luma plane (DCT/quantization only, no color conversion or chroma path). Entropy coding is not simulated, so results approximate — but do not bit-match — a real JPEG codec round trip.
Reference: mimics
torchvision.transforms.v2.functional.jpeg(approximately; torchvision runs a real libjpeg round trip on the CPU). Algorithm ported from NVIDIA DALI’sJpegCompressionDistortionGPU kernel (dali/kernels/imgproc/jpeg, Apache-2.0).Limitations:
Input: Data Layout: [NVCV_TENSOR_NHWC, NVCV_TENSOR_HWC, NVCV_TENSOR_NCHW, NVCV_TENSOR_CHW] 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
No
64bit Float
No
Output: Data Layout: [NVCV_TENSOR_NHWC, NVCV_TENSOR_HWC, NVCV_TENSOR_NCHW, NVCV_TENSOR_CHW] 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
No
64bit Float
No
Input/Output dependency
Property | Input == Output -------------- | ------------- Data Layout | Yes Data Type | Yes Number | Yes Channels | Yes Width | Yes Height | Yes
quality Tensor
Must be rank-1 ('N') and packed, with one value per image (length == batch size). Data Type must be TYPE_S32. Values are clamped to [1, 100] on the device (matching NVIDIA DALI); they are not validated on the host.
- Parameters:
handle – [in] Handle to the operator.
Must not be NULL.
stream – [in] Handle to a valid CUDA stream.
in – [in] Input tensor.
out – [out] Output tensor.
quality – [in] Per-image JPEG quality tensor, from 1 (strongest distortion) to 100 (weakest). See the quality Tensor requirements above.
- 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 cvcudaJpegCompressionDistortionScalarSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out, int32_t quality)
Executes the JpegCompressionDistortion operation with a single quality for the whole batch.
This parameter-tensor-free variant passes
qualityby value, avoiding a device parameter tensor. Semantics and Limitations are identical to cvcudaJpegCompressionDistortionSubmit, except that the scalar quality is validated on the host: values outside [1, 100] are rejected with NVCV_ERROR_INVALID_ARGUMENT (matching torchvision’s argument validation) instead of being clamped.- Parameters:
handle – [in] Handle to the operator.
Must not be NULL.
stream – [in] Handle to a valid CUDA stream.
in – [in] Input tensor.
out – [out] Output tensor.
quality – [in] JPEG quality applied to all images, from 1 (strongest distortion) to 100 (weakest). Must be in [1, 100].
- 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 cvcudaJpegCompressionDistortionVarShapeSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVImageBatchHandle in, NVCVImageBatchHandle out, NVCVTensorHandle quality)
Executes the JpegCompressionDistortion operation on a variable-shape image batch.
Semantics, data-type and channel constraints match cvcudaJpegCompressionDistortionSubmit. All images in a batch must share one image format, which must be RGB(8) for 3 channels (packed or planar) or U8/Y8 for 1 channel, without chroma subsampling or extra channels.
- 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 image batch.
quality – [in] Per-image JPEG quality tensor, from 1 (strongest distortion) to 100 (weakest). Must be rank-1, packed, TYPE_S32, with one value per image; values are clamped to [1, 100] on the device.
- 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 cvcudaJpegCompressionDistortionVarShapeScalarSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVImageBatchHandle in, NVCVImageBatchHandle out, int32_t quality)
Executes the JpegCompressionDistortion operation on a variable-shape image batch with a single quality for the whole batch.
Semantics match cvcudaJpegCompressionDistortionVarShapeSubmit; the scalar quality is validated on the host like cvcudaJpegCompressionDistortionScalarSubmit.
- 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 image batch.
quality – [in] JPEG quality applied to all images, from 1 (strongest distortion) to 100 (weakest). Must be in [1, 100].
- 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 cvcudaJpegCompressionDistortionCreate(NVCVOperatorHandle *handle)