Question

In: Computer Science

python- please finish the three programs, where one flips an image horizonally, then vertically, and one...

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

Solutions

Expert Solution

  • Inorder to do a horizontal flip, follow this process.
    • create a numpy array with same shape as the image.
    • move all the columns of image to the numpy array in reverse order
    • return the numpy array
  • Inorder to do a vertical flip, follow this process.
    • create a numpy array with same shape as the image.
    • move all the rows of image to the numpy array in reverse order
    • return the numpy array
  • Inorder to rotate right, followe this process.
    • create a numpy array, whose number of rows is number of columns in image and whose number of rows is number of columns in image.
    • copy all the rows in image and assign them to columns in the array in reverse order.
    • return the array

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()


Related Solutions

In three independent flips of a coin where there is a 54​% chance of flipping a...
In three independent flips of a coin where there is a 54​% chance of flipping a tail​, let A denote​ {first flip is a tail​}, BE denote​ {second flip is a tail​}, C denote​ {first two flips are tail​s}, and D denote​ {three tails on the first three​ flips}. Find the probabilities of​ A, B,​ C, and​ D, and determine​ which, if​ any, pairs of these events are independent. ​P(A)equals nothing ​(Round to two decimal places as​ needed.) ​P(B)equals nothing...
PYTHON - please finish the methods below that are apart of a linkedlist class #return the...
PYTHON - please finish the methods below that are apart of a linkedlist class #return the data value at index(position) in the list. values remain unchanged def __getpos__(self, position): #do not change, checks for valid index if self.size == 0: raise IndexError elif position is None: return self.pop(self.size - 1) elif type(position) != int: raise TypeError elif position < 0 or position >= self.size: raise IndexError #replace the data value at requested position(index). return nothing def __setpos__(self,position,value): #do not change,...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
Consider two Images of same dimensions where one image is an original image and other should...
Consider two Images of same dimensions where one image is an original image and other should be a degraded image.    Write a matlab program to measure picture quality using objective assessment validation criteria for the degraded image and original image. Calculate MSE, PSNR, Normalized absolute error, Maximum Difference, Structural content, Average difference, Normalized cross correlation for the images.    Explain the importance of Objective assessment in Image processing
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
Write a python function image compress() that takes one argument called filename, which is the name...
Write a python function image compress() that takes one argument called filename, which is the name of a file that contains a N × N (N-pixel by N-pixel) “grayscale bitmap image”. A “grayscale bitmap image” is an image of the following form where every pixel contains a grayscale color value between 0 − 255 (inclusive). Colour value 0 means that pixel should appear completely black and color value 255means completely white. Any other value in between stands for different shades...
1-Please complete the below python programs. Use spaces for indentations since the website does not take...
1-Please complete the below python programs. Use spaces for indentations since the website does not take tabs. #inputs to the function are 2 numbers x and y. Print "Sum 6!" if the sum of x and y is bigger or equal to 6. Print "Sum too small!" otherwise. def sum_6(x,y): #your answer here, can be multiple lines ___ #input to the function is a list of integers. The function will calculate and return a resultlist with the square of each...
python: modify an image (just show me how to write the two functions described below) 1.One...
python: modify an image (just show me how to write the two functions described below) 1.One way to calculate the contrast between two colours is to calculate the brightness of the top pixel (the average of the red, green and blue components, with all three components weighted equally), and subtract the brightness of the pixel below it. We then calculate the absolute value of this difference. If this absolute value is greater than a threshold value, the contrast between the...
step by step in python please Madlibs: A children's game where someone is prompted for a...
step by step in python please Madlibs: A children's game where someone is prompted for a series of words of particular types (e.g., nouns, verbs, colors, animals, etc.) and then those words are inserted into a "story" often creating funny outcomes. Write a Madlib program that will prompt a user for the following types of words in this order: Noun, Food, Food, Verb, Adverb, Adjective, Plural Noun, Color, Verb, Verb, Noun, Female Name, Plural Noun Using those inputs, output the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT