In PIL the highest quality resize from what I've seen seems to be:
img = img.resize((n1, n2), Image.ANTIALIAS)
For openCV this seems to be the way to do it:
small = cv2.resize(image, (0,0), fx=0.5, fy=0.5)
So my question is, is there an additional parameter needed or will this reduce the size with least quality lost?
OpenCV Python – Resize image. Resizing an image means changing the dimensions of it, be it width alone, height alone or changing both of them. Also, the aspect ratio of the original image could be preserved in the resized image.
dsize : It is the desired size of the output image, it can be a new height and width. fx : Scale factor along the horizontal axis. fy : Scale factor along the vertical axis. interpolation : It gives us the option of different methods of resizing the image.
INTER_CUBIC) , where fx is the scaling factor along the horizontal axis and fy along the vertical axis.
From the documentation:
To shrink an image, it will generally look best with CV_INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with CV_INTER_CUBIC (slow) or CV_INTER_LINEAR (faster but still looks OK).
The default for resize is CV_INTER_LINEAR
. Change the interpolation to CV_INTER_AREA
since you wish to shrink the image:
small = cv2.resize(image, (0,0), fx=0.5, fy=0.5, interpolation = cv2.INTER_AREA)
You may wish to compare the results of both interpolations for visual verification that you are getting the best quality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With