Asked by Aon
on 14 Sep 2018 at 15:03

In a multi-line binary image with different slopes and center points. How do you find the coordinate where most lines intersect? (it should be close where the red arrow points)

Thanks in advance

Answer by jonas
on 14 Sep 2018 at 19:57

Edited by jonas
on 15 Sep 2018 at 17:17

Accepted Answer

A good solution would be to identify each line by e.g. Hough transform, determine each intersection (e.g. **InterX** ) and then find the cluster with the highest density of intersections using e.g **hist3**.

In this case, it seems the point of interest is also the point with the highest density of white pixels, so you could apply some smoothing filter and then find the highest value in the matrix. Here's an example using a very simple 10x10 pixel average.

w=ones(10,10); A=conv2(I,w/numel(w),'same') imagesc(A) colormap(gca,'jet')

jonas
on 15 Sep 2018 at 16:59

Nice! You could put the intersections in a binary matrix, smooth it and find the highest value in the resulting matrix, just like I did in the original answer.

Better yet, use **hist3** to find the bin with highest density of points. Something like

[count,bin]=hist3([x,y],'cdatamode','auto'); [idx,idy]=find(count==max(count(:))); xmax=bin{1}(idx); ymax=bin{2}(idy);

and adjust the bin size to get the desired resolution.

Aon
on 16 Sep 2018 at 12:29

hist3 worked very well! Thank you very much for the help.

jonas
on 16 Sep 2018 at 13:23

Nice! My pleasure

Sign in to comment.

Answer by Image Analyst
on 15 Sep 2018 at 17:32

Have you considered dbscan?

https://en.wikipedia.org/wiki/DBSCAN

MATLAB Code for it:

https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=dbscan

Aon
on 16 Sep 2018 at 12:31

hist3 helped me very well but I will read more about dbscan also. Thank you!

Image Analyst
on 16 Sep 2018 at 13:42

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/419054-how-to-find-the-point-where-most-lines-intersect-in-a-binary-image#comment_610802

Do you have the lines equations, or endpoints? If not, how did you get this image? Can you get a listing of (x,y) crossing points?

## Aon (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/419054-how-to-find-the-point-where-most-lines-intersect-in-a-binary-image#comment_610818

I have the endpoints of the lines. Yes I have an array with the crossing points generated by the InterX function.

Can I find the cluster with only the array?

## jonas (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/419054-how-to-find-the-point-where-most-lines-intersect-in-a-binary-image#comment_610820

So basically you have a set of points where the lines meet? That would be relevant information to include in the original submission... or perhaps you tried this after posting the Q.

## Aon (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/419054-how-to-find-the-point-where-most-lines-intersect-in-a-binary-image#comment_610832

Yes with the help of InterX function I now have an array with the intersectpoints. Is it possible to find the cluster with only the array?

## jonas (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/419054-how-to-find-the-point-where-most-lines-intersect-in-a-binary-image#comment_610834

Yep, see the latest comment on the answer for two methods. Id try hist3 first

Sign in to comment.