PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.53k stars 1.02k forks source link

height argument ignored in imutils.resize() when width argument is set #286

Open abstractionmage opened 1 year ago

abstractionmage commented 1 year ago

Steps to reproduce:

  1. Load an image with an aspect ratio of 16 to 9
  2. call resized_image = imutils.resize(image, width=400, height=300)

Expected Behavior:

resized_image should have a resolution of 400 by 300 pixels

Actual Behavior:

resized_image has a resolution of 400 by 255 pixels

msavinash commented 8 months ago

I think this is the intended behavior of the resize function of imutils, to maintain the original aspect ratio of the image while resizing. We can either suggest this as a feature or close the issue.

abstractionmage commented 8 months ago

Even if this behavior is intended, right now this is just not obvious. I would at least add a docstring to the resize function, adding a note that the aspect ratio is maintained as well as a hint to the @param description of the height argument stating that it is ignored if a width is given.

Maybe I can make a small PR for this later.

Though I would argue that if I as a user wanted the aspect ratio to be kept, I simply wouldn't specify a width and height that would break it. But if I wanted the aspect ratio to change, shouldn't I be able to use imutil's resize function as well rather than having to find one from a different library that allows me to do that?

So yeah, I would be in favor of a feature request. Maybe we could introduce a new optional argument to the resize function keep-aspect=True to keep the feature backwards-compatible

msavinash commented 8 months ago

Sounds good. Maybe I can work on it once the PR is done. Currently users have to switch between OpenCV and Imutils for different types of resizing. I liked the idea of using a parameter like "keep-aspect"

msavinash commented 8 months ago

However I am not sure is the project is still active, the last commit seems to be made two years ago.