Accelerating the pace of engineering and science

# houghpeaks

Identify peaks in Hough transform

## Syntax

peaks = houghpeaks(H, numpeaks)
peaks = houghpeaks(..., param1, val1, param2, val2)

## Description

peaks = houghpeaks(H, numpeaks) locates peaks in the Hough transform matrix, H, generated by the hough function. numpeaks is a scalar value that specifies the maximum number of peaks to identify. If you omit numpeaks, it defaults to 1.

The function returns peaks, a Q-by-2 matrix, where Q can range from 0 to numpeaks. Q holds the row and column coordinates of the peaks.

peaks = houghpeaks(..., param1, val1, param2, val2) specifies parameter/value pairs, listed in the following table. Parameter names can be abbreviated, and case does not matter.

Parameter

Description

'Threshold'

Nonnegative scalar value that specifies the threshold at which values of H are considered to be peaks. Threshold can vary from 0 to Inf. Default is 0.5*max(H(:)).

'NHoodSize'

Two-element vector of positive odd integers: [M N]. 'NHoodSize' specifies the size of the suppression neighborhood. This is the neighborhood around each peak that is set to zero after the peak is identified. Default: smallest odd values greater than or equal to size(H)/50.

## Class Support

H is the output of the hough function. numpeaks is a positive integer scalar.

## Examples

Locate and display two peaks in the Hough transform of a rotated image.

I  = imread('circuit.tif');
BW = edge(imrotate(I,50,'crop'),'canny');
[H,T,R] = hough(BW);
P  = houghpeaks(H,2);
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
plot(T(P(:,2)),R(P(:,1)),'s','color','white');