![]() |
VOOZH | about |
OpenCV provides the cv2.resize() function, which allows you to resize images efficiently. By selecting different interpolation methods, you can control the balance between image quality and resizing speed.
cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
Parameters:
Return Value: Returns a resized image as a NumPy array, which can be displayed, saved, or further processed.
Note: Use either dsize or fx/fy for scaling, dsize: when you know exact width & height and fx/fy: when you want to scale by a factor. Do not set both together (unless dsize=None)
Interpolation is the method used to decide pixel colors when an image is resized. Below are some methods:
Method | When to Use | Description |
|---|---|---|
cv2.INTER_AREA | Shrinking | Minimizes distortion while downscaling. |
cv2.INTER_LINEAR | General resizing | Balances speed and quality |
cv2.INTER_CUBIC | Enlarging | Higher quality for upscaling |
cv2.INTER_NEAREST | Fast resizing | Quick but lower quality |
Output
Explanation: