Question: def sharpen(image, degree, threshold): Builds and returns a sharpened image. Expects an image and two integers (the degree to which the image should be sharpened

def sharpen(image, degree, threshold): """Builds and returns a sharpened image. Expects an image and two integers (the degree to which the image should be sharpened and the threshold used to detect edges) as arguments.""" def average(triple): """Returns the average of the values in the tuple.""" (r,g,b) = triple return (r+g+b) // 3 new = image.clone() for y in range(image.getHeight() - 1): for x in range(1, image.getWidth()): oldPixel = # use image.getPixel to get the pixel value at x & y leftPixel = # use image.getPixel to get the pixel value at x - 1 & y bottomPixel = # use image.getPixel to get the pixel value at x & y + 1 oldLum = average(oldPixel) leftLum = average(leftPixel) bottomLum = average(bottomPixel) if abs(oldLum - leftLum) > threshold or abs(oldLum - bottomLum) > threshold: new.setPixel(x, y, (max(oldPixel[0] - degree, 0), max(oldPixel[1] - degree, 0), max(oldPixel[2] - degree, 0))) return new def main(): filename = input("Enter the image file name: ") image = Image(filename) # Now, that you have sharpen use it to sharpen some images, like "smokey.gif" # YOU MUST put in AT LEAST use of your sharpen function. Vary the degree and threshold and see what happens... if __name__ == "__main__": main() 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!