Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Code, please include main: The edge-detection function described in this chapter returns a black-and-white image. Think of a similar way to transform color values

Python Code, please include main:

The edge-detection function described in this chapter returns a black-and-white image. Think of a similar way to transform color values so that the new image is still in its original colors but the outlines within it are merely sharpened. Then, define a function named sharpen that performs this operation. The function should expect an image and two integers as arguments. One integer should represent the degree to which the image should be sharpened. The other integer should represent the threshold used to detect edges. (Hint: A pixel can be darkened by making its RGB values smaller.)

edge-detection function :

image text in transcribed

def detectEdges (image, amount): " Builds and returns a new image in which the edges of the argument image are highlighted and the colors are reduced to black and white."* def average (triple): (r, g, b)triple return (rg b) 3 blackPixel-(0, 0, 0) whitePixel (255, 255, 255) new = image.clone() for y in range (image.getHeight) 1): for x in range (1, image.getwidth)) oldPixel image.getPixel(x, y) leftPixel image . getPixel(x - 1, y) bottomPixel-image.getPixel(x, y+ 1) oldLum average (oldPixel) leftLum average(leftPixel) bottomLum average (bottomPixel) if abs (oldLum leftLum) > amount or abs (oldLum bottomLum) amount: new.setPixel(x, y, blackPixel) else: new.setPixel(x, y, whitePixel) return new def detectEdges (image, amount): " Builds and returns a new image in which the edges of the argument image are highlighted and the colors are reduced to black and white."* def average (triple): (r, g, b)triple return (rg b) 3 blackPixel-(0, 0, 0) whitePixel (255, 255, 255) new = image.clone() for y in range (image.getHeight) 1): for x in range (1, image.getwidth)) oldPixel image.getPixel(x, y) leftPixel image . getPixel(x - 1, y) bottomPixel-image.getPixel(x, y+ 1) oldLum average (oldPixel) leftLum average(leftPixel) bottomLum average (bottomPixel) if abs (oldLum leftLum) > amount or abs (oldLum bottomLum) amount: new.setPixel(x, y, blackPixel) else: new.setPixel(x, y, whitePixel) return new

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

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions