Question: The edge-detection function (detectEdges) described in Chapter 7 and shown below returns a black and white image. Think of a similar way to transform color
The edge-detection function (detectEdges) described inChapter 7and shown below 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.
defdetectEdges(image,amount): """Buildsandreturnsanewimageinwhichtheedgesof theargumentimagearehighlightedandthecolorsare reducedtoblackandwhite.""" defaverage(triple): (r,g,b)=triple return(r+g+b)//3 blackPixel=(0,0,0) whitePixel=(255,255,255) new=image.clone() foryinrange(image.getHeight()-1): forxinrange(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) ifabs(oldLum-leftLum)>amountor\ abs(oldLum-bottomLum)>amount: new.setPixel(x,y,blackPixel) else: new.setPixel(x,y,whitePixel) returnnew
Then, define a function namedsharpenthat 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.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
