Generation

generate functionTue, 18 Apr 2023

Write and test a function named sepia that converts a color image to sepia. This function should first call grayscale to convert the color image to grayscale. A code segment for transforming the grayscale values to achieve a sepia effect follows. Note that the value for green does not change.

def sepia(oldPixel): red = oldPixel.getRed() blue = oldPixel.getBlue() green = oldPixel.getGreen() if red < 63: red = red * 1.1 blue = blue * 0.9 elif red < 192: red = red * 1.15 blue = blue * 0.85 else: red = red * 1.08 if blue > 0: blue = blue * 0.93 newPixel = Pixel(red, green, blue) return newPixel

Questions about programming?Chat with your personal AI assistant