Reputation: 1
I'm using OpenCV with Python to process images for AI training. I need to scale the images down to 32×32 pixels, but with cv2.resize()
the images come out too noisy. It looks like this function takes the value of a single pixel from each region of the image, but I need an average value of each region so that the images are less noisy. Is there an alternative to cv2.resize()
? I could just write my own function but I don't think it would be very fast.
Upvotes: 0
Views: 2077
Reputation: 28619
As you can see in the cv2.resize
documentation, the last parameter interpolation
determines the way the image is resampled.
See also the possible values for it.
The default is cv2.INTER_LINEAR
meaning a linear interpolation. It can create a blurred/noisy effect when the image is downsampled.
You can try to use other interpolation methods to see if the result is better suited for your needs.
Sepcifically I recommend you to try the cv2.INTER_NEAREST
option. It will determine the destination pixel value based on the color of the nearest pixel in the source. The downsampled image should be pixellated, but not blurred.
Another option is cv2.INTER_AREA
as mentioned in @fmw42's comment.
Upvotes: 2