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()

from images import Image def sharpen(img, threshold, amount): newimg = img.clone() w = img.getWidth() h = img.getHeight() for x in range(1, w-1): for y in range(1, h-1): p = img.getPixel(x, y) left = img.getPixel(x-1, y) above = img.getPixel(x, y-1) right = img.getPixel(x+1, y) below = img.getPixel(x, y+1) r = p.getRed() g = p.getGreen() b = p.getBlue() leftr = left.getRed() leftg = left.getGreen() leftb = left.getBlue() abover = above.getRed() aboveg = above.getGreen() aboveb = above.getBlue() rightr = right.getRed() rightg = right.getGreen()

Questions about programming?Chat with your personal AI assistant