1. Home
  2. Docs
  3. Computer Vision
  4. Introduction to OpenCV
  5. Manipulating the images

Manipulating the images

Copying the images

id –  to find the object’s memory address

  • When the object array “baboon” is assigned to “A”, then the id of A is same as baboon
  • If the method copy() is applied and assigned it to “B”, then then the memory address is different
baboon[:,:,] = 0
  • The above statement, makes the array “baboon” and “A” to be zero because they are pointing to the same memory location.
  • But the array “B” remains same

Flipping Images – PIL

  • Flipping images changes the orientation
  • The image can be flipped by changing the index value of a pixel or intensity
  • For color images, we can convert all the color channels at the same time
  • PIL
    • PIL have several ways to flip the image.
    • ImageOps Module
from PIL import ImageOps
im_flip = ImageOps.flip(image)
im_mirror= ImageOps.mirror(image)
image.transpose(Image.FLIP_TOP_BOTTOM)
ImageOps Module has built-in attributes to determine type of flip.
FLIP_TOP_BOTTOM – flip the image upside down

Flip – vertical

Vertical flip reverses the order of rows

from PIL import ImageOps
image = Image.open("baboon.jpg")
im_flip = ImageOps.flip(image)
im_flip

Mirror – Horizontal Flip

Horizontal flip reverses the order of columns

im_mirror = ImageOps.mirror(image)
im_mirror

Transpose

image.transpose(Image.FLIP_TOP_BOTTOM)
  • FLIP_TOP_BOTTOM to flip the image vertically
  • FLIP_LEFT_RIGHT to flip the image horizontally (mirror)

Loading

Views: 1

Articles

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments