Cv::resize
lastmod 2023-01-02created 2022-06-142 edits
Resizing - Scale transformation
Synopsis
Arguments
- src: input image
- dsize: output image size. A (w, h) tuple. If (0, 0), it is determined from fx and fy.
- dst: output image
- fx, fy: scale factor in the x and y directions. (Valid when dsize is 0)
- interpolation: specifies the interpolation method. Default is cv2.INTER_LINEAR
Interpilation flags
- cv2.INTER_NEAREST
- Nearest neighbor interpolation
- Fastest, but the quality is much worse. So it is rarely used.
- cv2.INTER_LINEAR
- Bilinear interpolation (uses 2x2 neighboring pixels)
- Uses 4 pixels. The most efficient. Fast, with reasonable quality.
- cv2.INTER_CUBIC
- Bicubic convolution interpolation (uses 4x4 neighboring pixels)
- Uses 16 pixels. Slower than cv2.INTER_LINEAR, but better quality.
- cv2.INTER_LANCZOS4
- Lanczos interpolation (uses 8x8 neighboring pixels)
- Uses 64 pixels. More complex and takes longer, but good quality.
- cv2.INTER_AREA
- Effective for shrinking images
- Builds the output image from area information. Used when shrinking an image.
Examples
Shrink by half:
Resize to 100x50: