Question
I need to implement the following function that converts and image from colored to grayscale or sepia. Not entirely sure how this can be done.
I need to implement the following function that converts and image from colored to grayscale or sepia. Not entirely sure how this can be done.
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 """ # enforce the precondition for sepia # Change this to return True when the function is implemented #Hint: do not need to add an if-statement for grayscale #when sepia is True: if sepia == True: return False
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