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, threshhold, factor): for y in range(image.getHeight()): for x in range(image.getWidth()): pixel = image.getPixel(x, y) if y == 0 or x == 0 or y == image.getHeight()-1 or x == image.getWidth() -1: continue right = image.getPixel(x+1, y) left = image.getPixel(x-1, y) top = image.getPixel(x, y-1) bottom = image.getPixel(x, y+1) r = right.getRed() - pixel.getRed() g = right.getGreen() - pixel.getGreen() b = right.getBlue() - pixel.getBlue() if r > threshhold or r < -threshhold: pixel.setRed(pixel.getRed() + factor * r) if g > threshhold or g < -threshhold: pixel.setGreen(pixel.get

Questions about programming?Chat with your personal AI assistant