Joseph Drackey

Generation

generate functionThu, 30 Mar 2023

Complete this program with a sharpen function that sharpens the edge of an image while keeping its original colors: from images import Image def main(): filename = input("Enter the image file name: ") image = Image(filename) newimage = sharpen(image, 20, 15) newimage.draw() if __name__ == "__main__": main()

def sharpen(image, width, height): original_image = image for y in range(height, original_image.getHeight() - height): for x in range(width, original_image.getWidth() - width): (red, green, blue) = original_image.getPixel(x, y) red2 = original_image.getPixel(x - 1, y) red4 = original_image.getPixel(x + 1, y) red5 = original_image.getPixel(x, y - 1) red6 = original_image.getPixel(x, y + 1) sharpred = red * 4 - red2[0] - red4[0] - red5[0] - red6[0] if sharpred < 0: sharpred = 0 elif sharpred > 255: sharpred = 255 green2 = original_image.getPixel(x - 1, y) green4 = original_image.getPixel(x + 1, y) green5

Questions about programming?Chat with your personal AI assistant