Edge Detection

Article Info

Pseudocode

PROCEDURE edge_detect(image)
    FOR x = 0 .. width DO
        FOR y = 0 .. height DO
            c = pixel(x, y)
            t = sum(c)

            c_down = pixel(x, y+1)
            t_down = sum(c_down)

            c_right = pixel(x+1, y)
            t_right = sum(c_right)

            if abs(t - t_down) > 20 and abs(t - t_right) > 20:
                pixel(x, y) <- (255, 255, 255)
            else:
                pixel(x, y) <- (0, 0, 0)

        END FOR
    END FOR
END PROCEDURE

Description

Loop through all pixels in the image, calculate the average (mean) value for that pixel then set the pixel values for all channels to be the calculated value.

There are many ways to calculate what this new value should be, any value where all the channels are the same value will create a black and white image.

Pixel Calculation

To calculate the threshold, we calculate the sum of the components of the pixel.

\[v = \sum_iP_i\]

We then calculate the distance between the pixel and its neighbours.

Acknowledgements

Adapted from Pseudocode produced for COMP120 by Dr. Micheal Scott.

Graduation Cap Book Open book GitHub Info chevron-right Sticky Note chevron-left Puzzle Piece Square Lightbulb Video Exclamation Triangle Globe