Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downsampling without smoothing

Tags:

opencv

Is there a built-in way to downsample an image in OpenCV 2.3.1 without prior Gaussian smoothing (which is performed by pyrDown C++ function).

Thanks.

like image 669
Vadim Kantorov Avatar asked May 03 '12 13:05

Vadim Kantorov


People also ask

Why do people blur before downsampling?

Gaussian blurring is commonly used when reducing the size of an image. When downsampling an image, it is common to apply a low-pass filter to the image prior to resampling. This is to ensure that spurious high-frequency information does not appear in the downsampled image (aliasing).

Does downsampling reduce image quality?

According to Adobe, when you decrease the number of pixels (downsampling), the application removes data. When data is removed the image also degrades to some extent, although not nearly as much as when you upsample.

How can you prevent aliasing when downsampling an image?

To avoid aliasing, a signal must not contain frequencies that are higher than one half the sample rate. Likewise, an input image must not contain details that are smaller than one pixel in the output image. This can be accomplished by appropriately filtering the signal or blurring the image before resampling it.

Does downsampling cause aliasing?

If a discrete-time signal's baseband spectral support is not limited to an interval of width 2 π / M radians, downsampling by M results in aliasing. Aliasing is the distortion that occurs when overlapping copies of the signal's spectrum are added together.


1 Answers

Maybe you're looking for resize().

# Python code:
import cv2
large_img = cv2.imread('our_large_image.jpg')
small_to_large_image_size_ratio = 0.2
small_img = cv2.resize(large_img, # original image
                       (0,0), # set fx and fy, not the final size
                       fx=small_to_large_image_size_ratio, 
                       fy=small_to_large_image_size_ratio, 
                       interpolation=cv2.INTER_NEAREST)

Instead of interpolation=cv2.INTER_NEAREST you can use any of these interpolation methods.

like image 63
fireant Avatar answered Oct 04 '22 22:10

fireant