Table of Contents
show
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 code | Value |
0 | Flipping around x axis (Vertical flip)(top to bottom) |
1 | Flipping around y axis(horizontal flip) (left to right) |
-1 | Flipping 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
Views: 0