Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does cv2.resize() do if input width and height same as resize input and width?

Tags:

python

opencv

I like fast, compact code so I have a question about this:

def loader(input_path, new_img_width, new_img_height):
    input_image = tifffile.imread(input_path)
    input_image = cv2.resize(input_image, (new_img_width, new_img_height),
                           interpolation=cv2.INTER_NEAREST)
    return input_image

Do I need to add a conditional statement before the call to cv2.resize for the case where new_img_width and new_img_height are the same as in input_image or this conditional statement already in the cv2.resize code?

I don't want spend cycles resizing the image unless it's necessary.

like image 367
empty Avatar asked Aug 10 '18 17:08

empty


People also ask

What does cv2 resize does?

resize() function of OpenCV library cv2. Resizing, by default, does only change the width and height of the image. The aspect ratio can be preserved or not, based on the requirement. Aspect Ratio can be preserved by calculating width or height for given target height or width respectively.

Which function is used to resize an image in OpenCV?

OpenCV provides the function cv2. resize() to resize an image. Resizing in OpenCV is referred to as scaling. We can resize an image by specifying the image size or scaling factor.


1 Answers

From the source code of resize function, line 4082:

if (dsize == ssize)
{
    // Source and destination are of same size. Use simple copy.
    src.copyTo(dst);
    return;
}
like image 187
unlut Avatar answered Oct 16 '22 21:10

unlut