In: Computer Science
python- please finish the three programs, where one flips an image horizonally, then vertically, and one that rotates an image by 90 degrees. please don't use the functions .mirror() .flip() or .rotate() if possible. thanks
def horizontal(image):
"""Flip the specified image left to right and return the modified
image"""
return img
def vertical(image):
"""Flip the specified image upside down and return the modified
image"""
return image
def rotate_90(image):
"""Rotate the specified image 90 degrees to the right and return
the modified image"""
return image
fucntions:
import numpy as np
import cv2
def horizontal(image):
image2 = np.zeros([image.shape[0], image.shape[1], image.shape[2]],
np.uint8);
for i in range(image.shape[1]):
image2[:,i] = image[:,image.shape[1]-i-1]
return image2
def vertical(image):
image2 = np.zeros([image.shape[0], image.shape[1], image.shape[2]],
np.uint8);
for i in range(image.shape[0]):
image2[i,:] = image[image.shape[0]-i-1,:]
return image2
def rotate(image):
h,w,c = img.shape
image2 = np.zeros([w,h,c], dtype=np.uint8)
for i in range(h):
image2[:,h-i-1] = image[i,:]
return image2

outputs:
original image:
1.) horizantial flip.
funtion call:
img = cv2.imread("img1.png")
horflip = horizontal(img)
cv2.imshow(" horizontal flip",horflip)
cv2.waitKey(0)
cv2.destroyAllWindows()

2.) vertical flip:
funtion call:
img = cv2.imread("img1.png")
horflip = vertical(img)
cv2.imshow(" vertical flip",horflip)
cv2.waitKey(0)
cv2.destroyAllWindows()

3.) rotate right
function call:
img = cv2.imread("img1.png")
horflip = rotate(img)
cv2.imshow("rotate right",horflip)
cv2.waitKey(0)
cv2.destroyAllWindows()
