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)
_images/ec3137c8308ebefcfd5472e1a81fea434bfc903076aec94287e9ab660ac9cfaa.png

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)
_images/d872f1a326c9324969a630301696f8f9bfa2b4a268c3832548993f374ac924c1.png

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 v as its default value is 0.

flipped_img_horizontal = flip(img, v=0)

flipped_meme_horizontal = PImage.fromarray(flipped_img_horizontal.image)
display(flipped_meme_horizontal)
_images/9dfe03f30d71793333e697171f0496a85699b1833af3a655ee0acf2cae70cda8.png

In summary, the flip function in the visumorph package provides a versatile tool for image flipping operations.