Flipping
Introduction
Image flipping is a fundamental operation in image processing, allowing for transformations such as vertical or horizontal mirroring. The flip function from the visumorph package facilitates these transformations.
The flip function accepts an image and an optional parameter v (default is 0). If v=1, it performs vertical flipping; if v=0, it performs horizontal flipping. The function returns a visumorph Image object representing the flipped image.
This function finds applications in tasks such as creating mirrored versions for training machine learning models, or any scenario where flipping can enhance the dataset.
Importing libraries
Import the necessary libraries, including flip, load_image.
from visumorph import flip, load_image, Image
from PIL import Image as PImage
from IPython.display import display
Loading Input Image
Load sample images for testing using the load_image function.
img = load_image("../tests/img/raw/meme.jpg")
meme = PImage.fromarray(img.image)
display(meme)
Vertical Flipping
Apply vertical flipping using the flip function and display the transformed image.
flipped_img_vertical = flip(img, v=1)
flipped_meme_vertical = PImage.fromarray(flipped_img_vertical.image)
display(flipped_meme_vertical)
Horizontal Flipping
Apply horizontal flipping using the flip function and display the transformed image.
Note: We Could very well use the function without specifying a value for
vas its default value is0.
flipped_img_horizontal = flip(img, v=0)
flipped_meme_horizontal = PImage.fromarray(flipped_img_horizontal.image)
display(flipped_meme_horizontal)
In summary, the flip function in the visumorph package provides a versatile tool for image flipping operations.