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

Flipping Images

Flipping Images – OpenCV

  • OpenCV has several ways to flip
  • Use the function flip()
import cv2
im_flip = cv2.flip(image,0)
  • It takes the input as array, and the parameter flip code.
  • If the parameter flip code = 0, it will flip vertically around y axis
  • Use the function rotate()
import cv2
im_flip = cv2.rotate(image,cv2.ROTATE_90_CLOCKWISE)
  • It takes the input as array, and the parameter flip code.
  • If the parameter flip code = 0, it will flip vertically around y axis
  • ROTATE_90_CLOCKWISE – rotates the input image 90 degrees clockwise (top row becomes the rightmost column)

Image flipping

Image can be flipped either on x axis or y axis or both

cv2.flip(image to be flipped, flip_code)
Flip codeValue
0Flipping around x axis (Vertical flip)(top to bottom)
1Flipping around y axis(horizontal flip) (left to right)
-1Flipping around both axis
flipped_image = cv2.flip(new_img_r,0) 
plt.imshow(flipped_image)
flipped_image_1 = cv2.flip(new_img_r,1)
plt.imshow(flipped_image_1)
flipped_image_2 = cv2.flip(new_img_r,1)
plt.imshow(flipped_image_2)

To Save an image using OpenCV

type(flipped_image_2)
cv2,imwrite('NewFlippedImg.jpg'mflipped_image_2)

To display the images as large size in notebook

flg = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111)
ax.imshow(flipped_image_2)
figsize of (10,8) allows a blank canvas space of 10 by 8 inches

Loading

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments