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.
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.
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.
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;
}
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