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, radius, amount): new_image = image.clone() for y in range(image.getHeight()): for x in range(image.getWidth()): pixel = image.getPixel(x, y) new_pixel = new_image.getPixel(x, y) for i in range(3): color = pixel.getColor()[i] new_color = color * radius + (255 - radius) * (color / 255) * amount new_color = int(new_color) color_list = list(new_pixel.getColor()) color_list[i] = new_color new_pixel.setColor(color_list) return new_image

Questions about programming?Chat with your personal AI assistant