Joseph Drackey

Generation

generate functionWed, 29 Mar 2023

The edge-detection function (detectEdges) described in Chapter 7 and shown below returns a black and white image. Think of a similar way to transform color values so that the new image is still in its original colors but the outlines within it are merely sharpened. Then, define a function named sharpen that performs this operation. The function should expect an image and two integers as arguments. One integer should represent the degree to which the image should be sharpened. The other integer should represent the threshold used to detect edges. Start the code this way: from images import Image def sharpen(image, degree, threshold):

from images import Image def sharpen(image, degree, threshold): for x in range(image.getWidth()): for y in range(image.getHeight()): (red, green, blue) = image.getPixel(x, y) if (red <= threshold) and (blue <= threshold) and (green <= threshold): newred = 0 newgreen = 0 newblue = 0 else: newred = red + degree newgreen = green + degree newblue = blue + degree image.setPixel(x, y, (newred, newgreen, newblue)) return image

Questions about programming?Chat with your personal AI assistant