in Python 1 Write a function blankimageheight width that cre
in Python
1. Write a function blank_image(height, width) that creates and returns a 2-D list of pixels with height rows and width columns in which all of the pixels are green (i.e., have RGB values [0,255,0]). This function will be very easy to write if you take advantage of the create_uniform_image function that we’ve provided!
2. Write a function flip_vert(pixels) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list of pixels for an image in which the original image is “flipped” vertically. In other words, the top of the original image should now be on the bottom, and the bottom should now be on the top.
3.Write a function reduce(pixels) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents an image that is half the size of the original image. It should do so by eliminating every other pixel in each row (to reduce the image horizontally) and by eliminating every other row (to reduce the image vertically).
4.
Write a function transpose(pixels) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that is the transpose of pixels.
You should start by copy-and-pasting your transpose function from Problem 3 into ps8pr4.py. The only real change that you need to make to your earlier function is to change the helper function that gets called to create the new 2-D list. Make this version oftranspose call your blank_image function to create the new 2-D list. We also recommend changing the name of the variable matrix to pixels, but doing so is not essential.
5. Write two more functions, both of which should take a 2-D list pixels containing pixels for an image, and create and return a new 2-D list of pixels for an image that is a rotation of the original image
rotate_clockwise(pixels) should rotate the original image clockwise by 90 degrees.
rotate_counterclockwise(pixels) should rotate the original image counterclockwise by 90 degrees.
Solution
1)
def create_grid(height, width):
\"\"\" put your docstring here
\"\"\"
grid = []
for row_num in _____________:
grid += _________________ # add a whole row
return grid
Try testing your function by re-running the file and entering the following from the Shell:
>>> grid = create_grid(3, 5)
>>> grid
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
2)
