Main Content

Detect Corners in Image

This example shows how to detect corners in an image using the Corner Detection block.

Example Model

Open the Simulink® model.

modelname = 'ex_blkCornerDetection.slx';
open_system(modelname)

Read Input Image

The model reads an RGB input image using the Image From File block and converts it to an intensity image using the Color Space Conversion block.

Detect and Visualize Corners

To detect corners in the input image, the model uses the Corner Detection block. The block uses the Harris corner detection method, and the value of the Maximum number of corners parameter is 25.

The model uses a Draw Markers block and a Video Viewer block to display all the corners detected in the input image.

Filter Detected Corners

The displayed image shows some spurious corners within the dark background of the image. The model uses other blocks in the Filter Corner Points area to remove these spurious corners and retain the corners of the flower only. The Filter Corner Points area selects fixed-size, square regions of interest (ROIs) around each detected corner point, and then finds the mean value of each ROI. The mean values of ROIs around corners detected in the dark background are lower than the other ROIs. To filter these spurious corners, the model selects the desired number of corners from those corresponding to the ROIs with the highest mean values. The Filter Corner Points area includes these blocks:

  • Select ROI — This MATLAB Function (Simulink) block generates the specifications of the square ROIs around each detected corner. The specifications include the coordinates of the upper-left corner and the width and height parameters of each ROI in the form [ x y width height ]. Since each ROI is square, the values of the width and the height parameters are equal. The model uses a Constant (Simulink) block to set the width of each ROI to 50.

  • 2-D Mean — This block computes the mean value of each selected ROI in input image.

  • Select Corners — This MATLAB Function (Simulink) block selects the desired number of corner points corresponding to the ROIs with the highest mean values. The model uses a Constant (Simulink) block to set the desired number of corner points to 10.

Simulate and Display Results

To display the filtered corner points in the image, the model uses a Draw Markers block and a Video Viewer block. Simulate the model and display the results.

sim(modelname);