Overview
The Rescale algorithm is used to scale the input image by means of resampling its content to make it conform to the output image dimensions.
No pre-filtering is applied, it's expected that the input content doesn't have frequencies higher than the Nyquist limit to avoid aliasing artifacts when downsampling.
Several interpolation methods are available, allowing trade-offs between quality and performance.
Input Factor Output
\begin{align*} f_x &= 2/3 \\[5pt] f_y &= 3/2 \end{align*}
Implementation
For every output pixel, calculate the corresponding input pixel using the formula:
\[ \mathit{out}[x,y] = P(f_x x, f_y y) \]
where P depends on the interpolation method used.
Sampling operation considers that whole coordinates fall on pixel center.
C API functions
For list of limitations, constraints and backends that implements the algorithm, consult reference documentation of the following functions:
Usage
Language:
C/C++
Python
Import VPI module
Rescale the VPI image input so that output has 66% of the original width and height is increased 50%, all using the CUDA backend. It's using the linear interpolation. with vpi.Backend.CUDA:
output = input.rescale((input.width*2//3, input.height*3//2), interp=vpi.Interp.LINEAR, border=vpi.Border.ZERO)
Initialization phase
Include the header that defines the rescale function.
Declares functions that implement the Rescale algorithm.
Define the input image object.
struct VPIImageImpl * VPIImage
A handle to an image.
Create an output image with the new required size and same format as input. int32_t w, h;
VPIStatus vpiImageGetFormat(VPIImage img, VPIImageFormat *format)
Get the image format.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageGetSize(VPIImage img, int32_t *width, int32_t *height)
Get the image dimensions in pixels.
Create the stream where the algorithm will be submitted for execution.
struct VPIStreamImpl * VPIStream
A handle to a stream.
VPIStatus vpiStreamCreate(uint64_t flags, VPIStream *stream)
Create a stream instance.
Processing phase
Submit the algorithm to the stream along with all parameters. It'll be executed by the CUDA algorithm.
VPIStatus vpiSubmitRescale(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, VPIInterpolationType interpolationType, VPIBorderExtension border, uint64_t flags)
Changes the size and scale of a 2D image.
@ VPI_BACKEND_CUDA
CUDA backend.
@ VPI_BORDER_ZERO
All pixels outside the image are considered to be zero.
@ VPI_INTERP_LINEAR
Linear interpolation.
Optionally, wait until the processing is done.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
Cleanup phase
Free resources held by the stream and the input and output images.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
Consult the Rescale for a complete example.
For more information, see Rescale in the "C API Reference" section of VPI - Vision Programming Interface .
Performance
For information on how to use the performance table below, see Algorithm Performance Tables .
Before comparing measurements, consult Comparing Algorithm Elapsed Times .
For further information on how performance was benchmarked, see Performance Benchmark .
clear filters
Device:
Jetson AGX Orin
-
Streams:
1
2
4
8
References
Daniel Ruijters, Bart M. ter Romeny, Paul Suetens (2008) "Efficient GPU-Based Texture Interpolation using Uniform B-Spline"
Journal of Graphics Tools, 13:4 61-69.