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(original, width, height): blank = Image.blank(original.width, original.height) for y in range(height, original.height - height): for x in range(width, original.width - width): pixel = original.get_pixel(x, y) blank.set_pixel(x, y, pixel) # Find pixel, pixel to the left, and pixel above for y in range(height, original.height - height): for x in range(width, original.width - width): pixel = original.get_pixel(x, y) left = original.get_pixel(x-1, y) above = original.get_pixel(x, y-1) # Compute the sharpened color red = weighted_average(pixel.red, left.red, above.red) green = weighted_average(pixel.green, left.green, above.green) blue = weighted_average(pixel.blue, left.blue, above.blue) newpixel = Pixel

Questions about programming?Chat with your personal AI assistant