The computed dimension for the new image.Allowing us to preserve the aspect ratio of the image.Īfter that’s done, to resize the image, we need to call the cv2.resize function which takes in as an argument: Then to define the new dimension of the image, as we already know the image will have a width of 600 pixels, the new height will be gotten by multiplying the old height by the ratio (line 19), which is then converted into an Integer. In this scenario, since we want our image to have a width of 600 pixels, to conclude the ratio between the new width to the old width, we must divide 600 by the old width. To resize the image by setting the width, all that is required is to compute the resized ratio that’s needed to preserve the aspect ratio. Which is the relationship between the image’s width and its height:Īspect_ratio = image_width / image_heightĪs you have seen, our image will look distorted if we ignore the image’s aspect ratio while resizing (see Figure 1). Now to resize the image, we must keep in mind preserving the aspect ratio. Project Structureīefore we get started implementing our Python script for this tutorial, let’s first review our project directory structure:įigure 2: Displaying the original image to screen. And decreasing the size of the image leaves us with fewer pixels to process which saves time when working with image processing algorithms or deep learning models. That’s why you can see the image is been stretch either along the $ x $- axis or along the $ y $ – axis.Īpart from the aspect ratio, we also need to keep in mind, what interpolation method to use when resizing the image.Īs increasing the size of the pixels requires us to fill in the gaps of pixels we don’t even know exists. And on the right, we have both of the resized images without considering the aspect ratio of the image. And not having this in mind, can lead to having a squished or compressed image: Figure 1: Neglecting the aspect ratio of an image while resizing. Most of the times, a common mistake people make when resizing is neglecting the aspect ratio - which is the ratio of an image’s width to its height. Resizing, or also known as scaling refers to the process of either increasing or decreasing the size of an image in response to it’s width and height. What is Resizing and Why should you consider the Aspect Ratio ?
0 Comments
Leave a Reply. |