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.51k stars 1.03k forks source link

imutils.resize returns not appropriate size #229

Closed vvvin333 closed 3 years ago

vvvin333 commented 3 years ago

When I resize jpg-files to (2000,2000,3) from (3932,3933,3) with imutils.resize(x,2000,2000) I have got this image with (1999,2000,3) shape! But with cv2.resize(x, (2000,2000)) I have no such a problem.

jhfdevelop commented 3 years ago

Ok, just had the same problem and I think I figured it out:

The imutils.resize function is not really intended to take a width and a height argument simultaneously because the method preserves the aspect ratio. The idea is to specify one dimension as target and the other will be calculated. The documentation and the implementation make that very clear.

So if you want exact width and height dimensions you don't really need this function and you can call the cv2.resize function directly. If you want to preserve the aspect ratio though, just don't specify the dimension that you allow to change.

Also have a look at this pr

I hope this helps

vvvin333 commented 3 years ago

Thnx for reference to implementation.