For those of you wondering about the paper, it's:

*Rectangle Detection based on a Windowed Hough Transform* by ClĂˇudio Rosito Jung and Rodrigo Schramm.

Now according to the paper, the intersection points are expressed as polar coordinates, obviously you implementation may be different (the only way to tell is to show us your code).

Assuming you are being consistent with his notation, your peaks should be expressed as:

You must then perform peak paring given by equation (3) in section 4.3 or

where represents the angular threshold corresponding to parallel lines
and is the normalized threshold corresponding to lines of similar length.

If you have access to the Image Processing Toolbox, you can use the functions HOUGH, HOUGHPEAKS, and HOUGHLINES:

```
%# your binary image
BW = false(7,7);
BW([6 10 18 24 36 38 41]) = true;
%# hough transform, detect peaks, then get lines segments
[H T R] = hough(BW);
P = houghpeaks(H, 4);
lines = houghlines(BW, T, R, P, 'MinLength',2);
%# show accumulator matrix and peaks
imshow(H./max(H(:)), [], 'XData',T, 'YData',R), hold on
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);
xlabel('\theta'), ylabel('\rho')
axis on, axis normal
colormap(hot), colorbar
%# overlay detected lines over image
figure, imshow(BW), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off
```

## Best Solution

I think you meant the goal to be to detect lines in an image, not comparing two images (?).

Anyway, to find the maximum intensities in the Hough transform matrix generated by the

function, we use the`hough`

function, and pass it the desired number of peaks to detect.`houghpeaks`

## EDIT1:

I figured I would add an example to show the procedure:

## EDIT2:

Following your recent update, I managed to detect the lines by only making a few changes to the same above code:

`[200 70 160 140]`

Note: You will have to add the offset to get the position of the lines in the original image uncropped. Also, if you want more accurate results, you might want to detect four lines and get the lines in the middle as shown below: