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 values so that the new image is still in its original colors but the outlines within it are merely sharpened. 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 (r + g + 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 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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I already saw a solution to this problem here, but it is not correct

 

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 values so that the new image is still in its original colors but the outlines within it are merely sharpened.

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 (r + g + 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

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.)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Processes of 3D Graphics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY