Scaling
Introduction
The scale function is a pivotal tool in image processing, meticulously crafted to adjust an image’s size to meet specific aesthetic or analytical needs. Integrated within the visumorph package, this function excels in resizing images both efficiently and effectively, guided by a specified scale parameter.
This function’s key role is to resize an image based on the provided scale factor, resulting in a modified image size. It requires only one parameter - ‘scale’, which determines the new size of the image. Upon execution, it yields a visumorph Image object reflecting the adjusted dimensions.
Its applicability is wide-ranging and significant, spanning artistic image manipulation, enhancing data visualization techniques, and serving as a foundational step in machine learning processes, especially where adjusting or normalizing image size is imperative.
Importing libraries
In this segment, we incorporate the scale function and the visumorph module, which are instrumental for managing image-centric data structures and functionalities. We leverage the Python Imaging Library (PIL), aliased as PImage, to circumvent naming clashes, thereby unlocking potent image manipulation features. Additionally, the display function from IPython is utilized within the Jupyter notebook context. This facilitates an engaging and transparent demonstration of the scale function’s application, illustrating its effectiveness in achieving specific visual results in various image processing endeavors.
from visumorph import scale, load_image, Image
from PIL import Image as PImage
from IPython.display import display
Loading Input Image
This code demonstrates loading an image using load_image function. The image file should be in a format compatible with the library (JPG or PNG). Then, we use fromarray function of PIL to convert the image to PImage object so that we can display the image here.
img = load_image("../tests/img/raw/meme.jpg")
meme = PImage.fromarray(img.image)
display(meme)
Output Image
Utilizing the scale function from the visumorph package, we have the capability to modify the hue o an image to adjust its size. In this specific instance, by setting the scale parameter to 2, the updated image with be adjusted to size 2. The following image shows the updated image with scale size 2.
Enlarging Image
Increase the size of the image with a scale parameter > 1 With a scale parameter > 1, the original image’s size can be increased corresponding to the scale parameter
img_hue_1 = scale(img, 2)
meme_hue_1 = PImage.fromarray(img_hue_1.image)
display(meme_hue_1)
Shrinking Image
To illustrate the scale function’s capability is not limited to resizing the image bigger, it can be adjusted to resize the image down with scale parameter 0.5, effectively shrinking the image with a fractional number. By specifying the scale parameter to 0.5, the result is an image that retains the original structure and contours but is now uniformly shrinked to 0.5 of the original size.
img_hue_1 = scale(img, 0.5)
meme_hue_1 = PImage.fromarray(img_hue_1.image)
display(meme_hue_1)