Calculating perimeter/circumfrence of regions in a binary image through a different approach than regionprops(BW, 'perimeter') *UPDATED*
Show older comments
Suppose I have a binary image with many different regions in it. One region in the image may look like this:

Using regionprops and the 'perimeter' property, Matlab would calculate the green marked perimeter, which for this region would be 17.9460.
Now, what I want to calculate is a little bit different. It's basically the length of the lines forming the region (marked red in the image). Or in other words, the number of green marked "pixels" in the following image, although the blue marked pixles would have to be counted twice to get the length of the lines:

So this would get a length of all lines (or count of pixels) of 24.
Is there a way to do this using some build in Matlab functions in the Image Processing Toolbox?
Thanks in advance, Best Regards
5 Comments
Amith Kamath
on 10 Dec 2015
Philip: This is a very interesting question. Thanks for the helpful illustrations to show us what you are trying to achieve.
I'm however a little confused by this statement: "It's basically the length of the lines forming the region. Or in other words, the number of green marked "pixels"". Could you please elaborate on what you mean by 'length of lines forming the region'?
What happens at a corner, like in the second image, where a green pixel has a white pixel to it's north, north-east and east? There are two 'edges' this pixel is representing, but it will be counted only once in the scheme you mention. Should this not be counted twice, then?
Phillip Probst
on 15 Dec 2015
Edited: Phillip Probst
on 15 Dec 2015
Phillip Probst
on 15 Dec 2015
Edited: Phillip Probst
on 15 Dec 2015
Image Analyst
on 17 Dec 2015
You have to be careful of your definitions. For example in this: [0 1 1 1 0], what is the "length" of the line? Is it 3 or is it 2? You could make an argument for either. If two pixels are on a diagonal, is the length 2 or sqrt(2)?
Phillip Probst
on 21 Dec 2015
Accepted Answer
More Answers (1)
Image Analyst
on 10 Dec 2015
1 vote
Try calling imdilate() followed by bwboundaries() or regionprops(). Let me know what you find out.
1 Comment
Phillip Probst
on 15 Dec 2015
Edited: Phillip Probst
on 15 Dec 2015
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


