Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

1.what is rule of law? 2.The administrative body of government?

Answered: 1 week ago

Question

Write a short note on - JUDICIARY

Answered: 1 week ago