# # lab9extra5.py (Lab 9, Extra-practice exercise 5) # # Computer Science 111 # from hmcpng import * def create_uniform_image(height, width, pixel): """ creates and returns a 2-D list of pixels with height rows and width columns in which all of the pixels have the RGB values given by pixel inputs: height and width are non-negative integers pixel is a list of RBG values of the form [R,G,B], where each element is an integer between 0 and 255. """ pixels = [] for r in range(height): row = [pixel] * width pixels += [row] return pixels def remove_blue(pixels): """ takes the specified 2-D list of pixels (where each pixel is a list of the form [R,G,B]) and creates and returns a new 2-D list of pixels in which the blue component of each pixel is set to 0. input: pixel is a rectangular 2-D list of pixels """ height = len(pixels) width = len(pixels[0]) # Create a 2-D list that we'll use for the new image. # We start with a uniform image filled with green pixels, # but then we'll replace the green pixels with ones that # represent the pixels of the original image with blue removed. new_pixels = create_uniform_image(height, width, [0, 255, 0]) for r in range(height): for c in range(width): # Get the original pixel at row r, column c. pixel = pixels[r][c] # Create a new pixel in which the red and green components # are the same as in the original pixel, but the blue is removed, # and assign it to the appropriate location in new_pixels. new_pixels[r][c] = [pixel[0], pixel[1], 0] return new_pixels