Ask Your Question
1

What is the difference between cv2.resize() and imutils.resize()?

asked 2019-02-13 12:35:50 -0600

Nisha gravatar image

updated 2019-02-13 12:51:11 -0600

berak gravatar image

What is the difference between cv2.resize() and imutils.resize()

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2019-02-13 13:38:40 -0600

supra56 gravatar image

updated 2019-02-13 13:40:45 -0600

imutils.resize() evaluate width only but not height. Imutils never used height all times. While OpenCV used both width and height or either height or width. Here is imutils.py:

def resize(image, width = None, height = None, inter = cv2.INTER_AREA):
    # initialize the dimensions of the image to be resized and grab the image size
    dim = None
    (h, w) = image.shape[:2]
    # if both the width and height are None, then return the original image
    if width is None and height is None:
        return image
        # check to see if the width is None
        if width is None:
            # calculate the ratio of the height and construct the dimensions
            r = height / float(h)
            dim = (int(w * r), height)
        # otherwise, the height is None
        else:
            # calculate the ratio of the width and construct the dimensions
            r = width / float(w)
            dim = (width, int(h * r))
        # resize the image
        resized = cv2.resize(image, dim, interpolation = inter)
        # return the resized image
        return resized
edit flag offensive delete link more
0

answered 2019-02-13 12:47:55 -0600

berak gravatar image

updated 2019-02-13 12:50:21 -0600

if i understand it correctly, imutils.resize() only tries to evaluate either the width or height argument, and tries to preserve the original aspect ratio of the image, while cv2.resize() gives you a free choice (w/o any constraints)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-02-13 12:35:50 -0600

Seen: 23,707 times

Last updated: Feb 13 '19