Main Content

cornermetric

(Not recommended) Create corner metric matrix from image

cornermetric is not recommended. Use detectHarrisFeatures (Computer Vision Toolbox) or detectMinEigenFeatures (Computer Vision Toolbox) and the cornerPoints (Computer Vision Toolbox) object in Computer Vision Toolbox™ instead. For more information, see Version History.

Description

C = cornermetric(I) creates a corner metric matrix by detecting corner features in the input image I.

example

C = cornermetric(I,method) creates a corner metric matrix by detecting corner features in the input image I. The corner detection method specified by method is used for finding the corner features.

example

C = cornermetric(___,Name=Value)specifies options using one or more name-value arguments in addition to the input arguments from any of the previous syntaxes.

example

Examples

collapse all

Read an input image into the workspace.

I = imread("circles.png");

Generate a corner metric matrix. Specify the filter coefficients. The corner detection method takes the default value "Harris".

filter = [0.25 0.5 0.25];
C = cornermetric(I,FilterCoefficients=filter);

Use imregionalmax to detect corner features (pixels) from the corner metric matrix.

corner_peaks = imregionalmax(C);

Set the value of the detected corner pixels to [255 0 0].

corner_idx = find(corner_peaks == true);
[r,g,b] = deal(I);
r(corner_idx) = 255;
g(corner_idx) = 0;
b(corner_idx) = 0;
RGB = cat(3,r,g,b);

Adjust the corner metric matrix for viewing.

C_adjusted = imadjust(C);

Display the original image, adjusted corner metric and the detected corner features as a montage. The detected corner features are displayed as red color pixels with RGB value as [255 0 0].

montage({I,C_adjusted,RGB},Size=[1 3])
title("Original Image vs. Adjusted Corner Metric Matrix vs. Detected Corner Features");

Figure contains an axes object. The hidden axes object with title Original Image vs. Adjusted Corner Metric Matrix vs. Detected Corner Features contains an object of type image.

Read an input image into the workspace.

I = imread("bag.png");

Generate a corner metric matrix. Specify the method as "MinimumEigenvalue".

C = cornermetric(I,"MinimumEigenvalue");

Use imregionalmax to detect corner features (pixels) from the corner metric matrix.

corner_peaks = imregionalmax(C);

Set the value of the detected corner pixels to [255 0 0].

RGB = labeloverlay(I,corner_peaks,Transparency=0,Colormap=[1 0 0]);

Adjust the corner metric matrix for viewing.

C_adjusted = imadjust(C);

Display the original image, adjusted corner metric and the detected corner features as a montage. The detected corner features are displayed as red color pixels.

montage({I,C_adjusted,RGB},Size=[1 3],BorderSize=5,BackgroundColor="w")
title("Original Image vs. Adjusted Corner Metric Matrix vs. Detected Corner Features");

Figure contains an axes object. The hidden axes object with title Original Image vs. Adjusted Corner Metric Matrix vs. Detected Corner Features contains an object of type image.

Input Arguments

collapse all

Input image, specified as a 2-D binary image or 2-D grayscale image of size m-by-n.

Data Types: single | double | uint8 | uint16 | uint32 | int8 | int16 | int32 | logical

Corner detection method, specified as either "Harris" or "MinimumEigenvalue". If the method is:

  • "Harris", the function creates corner metric matrix by using the Harris corner detector.

  • "MinimumEigenvalue", the function creates corner metric matrix by using the Shi and Tomasi's minimum eigenvalue approach.

If method is not specified, the default value set as "Harris" and the function uses Harris corner detector for detecting corner features.

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: cornermetric(I,SensitivityFactor=0.1) specifies a sensitivity factor of 0.1.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: cornermetric(I,"SensitivityFactor",0.1) specifies a sensitivity factor of 0.1.

Coefficients of 1-D spatial filter mask, specified as an n-element vector. The value of n must be odd and greater than or equal to 3. By default, the 1-D spatial filter mask is a 5-element vector and the default filter coefficients are computed using fspecial("gaussian",[5 1],1.5).

Sensitivity factor, specified as a numeric scalar in the interval (0, 0.25). For smaller values of sensitivity factor, the algorithm is more likely to detect sharper corners.

The SensitivityFactor argument is valid only if the input method is "Harris".

Output Arguments

collapse all

Corner metric matrix, returned as a m-by-n matrix of the same size as the input image I.

Data Types: double

Tips

The corner and cornermetric functions both detect corners in images. For most applications, use the streamlined corner function to find corners in one step. If you want greater control over corner selection, use the cornermetric function to compute a corner metric matrix. Then, write your own algorithm to find peak values in corner metric matrix.

Version History

Introduced in R2008b

collapse all

R2016a: cornermetric is not recommended

cornermetric is not recommended. Instead, use the detectHarrisFeatures (Computer Vision Toolbox) or detectMinEigenFeatures (Computer Vision Toolbox) and the cornerPoints (Computer Vision Toolbox) object in Computer Vision Toolbox.

Use detectHarrisFeatures (Computer Vision Toolbox) to find corners in an image by using the Harris corner detector method. Use detectMinEigenFeatures (Computer Vision Toolbox) to find corners in an image by using Shi and Tomasi's minimum eigenvalue method. The detectHarrisFeatures (Computer Vision Toolbox) and detectMinEigenFeatures (Computer Vision Toolbox) functions return the cornerPoints (Computer Vision Toolbox) object to which the detected corner points are stored.

See Also

|