Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started