How to calculate the length of image?
1 次查看(过去 30 天)
显示 更早的评论
Hi
Regarding the image below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153977/image.jpeg)
I want to calculate the length of the large black region, i.e., the perimeter of this region plus the length of the small white objects within it. How may I do so?
I know there are some functions for calculating the perimeter, but how to include the small objects?
Also please note that this is a binary image, but I can also do the calculations on grayscale image, if needed.
Thanks so much.
Steven
0 个评论
采纳的回答
Image Analyst
2013-12-22
Something is wrong with that image. I saved it but when I read it in it looks totally different. Anyway, you need to get the perimeters of everything with regionprops and sum them
measurements = regionprops(binaryImage, 'Perimeter');
allPerimeters = [measurements.Perimeter];
theSum = sum(allPerimeters);
But make sure the big perimeter is the inside one and not the outer edge of the image. If it is, then invert the image and fill holes before calling regionprops
binaryImage = imfill(~binaryImage, 'holes');
measurements = regionprops(binaryImage, 'Perimeter');
theBigPerimeter = measurements.Perimeter;
I can't really test it because, like I said, it seems the image is messed up.
4 个评论
Image Analyst
2013-12-22
There are different algorithms. Summing bwperim just sums up the pixels. regionprops computes the perimeter by calculating the distance between each adjoining pair of pixels around the border of the region. So the first method would have two pixels at 45 degrees to each other as a length of 2 while regionprops would give a distance of sqrt(2). You can use whichever method you like better. Optically the regionprops method is probably more accurate.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!