Question
Don't use append, python, no built-in functions helper function: def create_uniform_image(height, width, pixel): creates and returns a 2-D list of pixels with height rows
Don't use append, python, no built-in functions
helper function:
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 1-D 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 blank_image(height, width): """ creates and returns a 2-D list of pixels with height rows and width columns in which all of the pixels are green. inputs: height and width are non-negative integers """ all_green = create_uniform_image(height, width, [0, 255, 0]) return all_green
def brightness(pixel): """ takes a pixel (an [R, G, B] list) and returns a value between 0 and 255 that represents the brightness of that pixel. """ red = pixel[0] green = pixel[1] blue = pixel[2] return (21*red + 72*green + 7*blue) // 100
1. Write a function bw(pixels, threshold) 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 that is a black-and-white version of the original image. The second input to the function is an integer threshold between 0 and 255, and it should govern which pixels are turned white and which are turned black. The brightness of a pixel r,b,g] can be computed using this formula: 21r72g 7b We've given you a helper function called brightnessO that you should use to make this computation. If a pixel's brightness (as determined by the brightness) helper function) is greater than the specified threshold, the pixel should be turned white (C255,255,255]); otherwise, the pixel should be turned black (0,0,0]). For example, if you do the following: pixels-load_pixelsC'spam.png' >bwspambw(pixels, 100) save_pixels(bw spam, 'bw.spam.png') bw spam.png saved you should obtain the following image: SPAM 1. Write a function bw(pixels, threshold) 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 that is a black-and-white version of the original image. The second input to the function is an integer threshold between 0 and 255, and it should govern which pixels are turned white and which are turned black. The brightness of a pixel r,b,g] can be computed using this formula: 21r72g 7b We've given you a helper function called brightnessO that you should use to make this computation. If a pixel's brightness (as determined by the brightness) helper function) is greater than the specified threshold, the pixel should be turned white (C255,255,255]); otherwise, the pixel should be turned black (0,0,0]). For example, if you do the following: pixels-load_pixelsC'spam.png' >bwspambw(pixels, 100) save_pixels(bw spam, 'bw.spam.png') bw spam.png saved you should obtain the following image: SPAM
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started