Main Content

Perform Edge Detection by Using a Neighborhood Processing Subsystem Block

This example shows how to detect edges in an image by using a Neighborhood Processing Subsystem block to implement Laplacian edge detection. Use edge detection to identify objects and features in an image.

Inspect Model

1. Open the model.

mdl = 'EdgeDetectionNeighborhoodExample';
open_system(mdl);

The model uses an Image From File (Computer Vision Toolbox) block to import an image of the moon, a Neighborhood Processing Subsystem block to perform edge detection, and two Video Viewer (Computer Vision Toolbox) blocks to display the image before and after processing.

2. Open the Neighborhood Processing Subsystem block.

The Neighborhood Processing Subsystem operates over a 3-by-3 neighborhood. To implement Laplacian edge detection, it uses a Gain block to multiply each neighborhood by this kernel:

[-1-1-1-18-1-1-1-1]

The Neighborhood Processing Subsystem block then uses a Sum of Elements block to sum the resulting matrix into a scalar value, then uses a Saturation block to saturate that scalar to the range [0, 255]. Pixels that represent edges in the image will have high values and saturate to 255 because they are different in brightness from the surrounding pixels.

Simulate Model and View Results

Simulate the model.

sim(mdl);

Figure Before contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The hidden axes object contains an object of type image.

Figure After contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The hidden axes object contains an object of type image.

The modified image has bright pixels corresponding to areas in the original image that have high rates of change in brightness and dark pixels corresponding to areas that have low rates of change.

See Also

Related Topics