![]() ![]() In the middle, we have resized the image to half its size - and other than the image being resized, there is no loss in image “quality.” However, on the right, we have dramatically increased the image size. In terms of “quality” of the output image, decreasing an image’s size is always easier (and more aesthetically pleasing) than increasing it. On the other hand, if we were to increase the size of the image, the interpolation function would have to “fill in the gaps” between pixels that previously did not exist.įor example, take a look at the image in Figure 2:įigure 2: Increasing and decreasing the size of an image with OpenCV. This is because the interpolation function simply has to remove pixels from an image. In general, it’s far more beneficial (and visually appealing) to decrease the size of the image. And the goal of an interpolation function is to take these neighborhoods of pixels and use them to either increase or decrease the size of the image. In this case, the “known points” are the pixels of our original image. ![]() The formal definition of interpolation is:Ī method of constructing new data points within the range of a discrete set of known data points. We also need to keep in mind the interpolation method of our resizing function. As we explore machine learning/deep learning techniques, we’ll find that our internal algorithms often ignore the aspect ratio of an image but more on that once we understand the fundamentals of computer vision. Exceptions most certainly do apply, though. In general, you’ll want to preserve the images’ aspect ratio when resizing - especially if these images are presented as output to the user. ![]() They have been resized by ignoring the ratio of the width to the height of the image. And on the right, we have two images that have been distorted by not preserving the aspect ratio. The corresponding code with the Python SDK will be image_url = imagekit.Figure 1: Ignoring the aspect ratio of an image can lead to resized images that look distorted, squished, and crunched. Similarly, if we want to get a 400 x 300px resized image from ImageKit, the URL will contain height and width transformation parameters. Print(f"Original size : ) Example of generating a URL at width 200px with the Python SDK Pillow provides the resize() method, which takes a (width, height) tuple as an argument. Install the latest version of Pillow with pip. Pillow is one of the most popular options for performing basic image manipulation tasks such as cropping, resizing, or adding watermarks. We will be using an image by Asad from Pexels for all examples in this article. The free plan has access to all the features we need for image resizing and other transformations. When we get to ImageKit later in this article, you will need to sign up for a free account on ImageKit's website. Make sure you have a recent version of Python installed on your system, preferably Python 3.6+, then spin up a virtual environment.
0 Comments
Leave a Reply. |