Question: I need to implement the bolded function and not sure where to start . I believe the first 2 functions are helper functions. The language
I need to implement the bolded function and not sure where to start. I believe the first 2 functions are helper functions. The language working with is python.
# Function useful for debugging def display(image): """ Returns False after pretty printing the image pixels, one pixel per line. All plug-in functions must return True or False. This function returns False because it displays information about the image, but does not modify it. You can use this function to look at the pixels of a file and see whether the pixel values are what you expect them to be. This is helpful to analyze a file after you have processed it. Parameter image: The image buffer Precondition: image is a 2d table of RGB objects """ height = len(image) width = len(image[0]) # Find the maximum string size for padding maxsize = 0 for row in image: for pixel in row: text = repr(pixel) if len(text) > maxsize: maxsize = len(text) # Pretty print the pixels print() for pos1 in range(height): row = image[pos1] for pos2 in range(width): pixel = row[pos2] middle = repr(pixel) padding = maxsize-len(middle) prefix = ' ' if pos1 == 0 and pos2 == 0: prefix = '[ [ ' elif pos2 == 0: prefix = ' [ ' suffix = ',' if pos1 == height-1 and pos2 == width-1: suffix = (' '*padding)+' ] ]' elif pos2 == width-1: suffix = (' '*padding)+' ],' print(prefix+middle+suffix) # This function does not modify the image return
# Example function illustrating image manipulation def dered(image): """ Returns True after removing all red values from the given image. All plug-in functions must return True or False. This function returns True because it modifies the image. This function sets the red value to 0 for every pixel in the image. Parameter image: The image buffer Precondition: image is a 2d table of RGB objects """ # Get the image size height = len(image) width = len(image[0]) for row in range(height): for col in range(width): pixel = image[row][col] pixel.red = 0 # This function DOES modify the image return True
def mono(image, sepia=False): """ Returns True after converting the image to monochrome. All plug-in functions must return True or False. This function returns True because it modifies the image. It converts the image to either greyscale or sepia tone, depending on the parameter sepia. If sepia is False, then this function uses greyscale. For each pixel, it computes the overall brightness, defined as 0.3 * red + 0.6 * green + 0.1 * blue. It then sets all three color components of the pixel to that value. The alpha value should remain untouched. If sepia is True, it makes the same computations as before but sets green to 0.6 * brightness and blue to 0.4 * brightness. Parameter image: The image buffer Precondition: image is a 2d table of RGB objects Parameter sepia: Whether to use sepia tone instead of greyscale Precondition: sepia is a bool """ # We recommend enforcing the precondition for sepia # Change this to return True when the function is implemented return False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
