MATLAB Answers

How can I calculate the number of the neighbours for each cell?

15 views (last 30 days)
Alaa
Alaa on 1 Mar 2016
Edited: Image Analyst on 2 Mar 2016
I want to calculate the percentage of hexagonal cells in a binary image, which means the number of the cells that have another 6 neighbours cells. I'm looking for a function that can do that in Matlab. I've tried different Matlab functions such as regionprops, and bwconncomp. However, no one works for me. is there any idea.
A simple image is here:

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 2 Mar 2016
Edited: Image Analyst on 2 Mar 2016
Threshold for black. Then call bwlabel(). Then call imdilate() to grow out the regions one layer until they touch. Then call graycomatrix to find out what number region touches each other number region. If they don't touch, the count will be zero in the result of graycomatrix(). Just sum up the number of non-zero columns to count the number of neighbors. No, I don't have a demo, so give it a try and share your code if you can't get it working.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!