Hi
Regarding the image below:
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

 채택된 답변

Image Analyst
Image Analyst 2013년 12월 22일

0 개 추천

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

Steven
Steven 2013년 12월 22일
편집: Steven 2016년 4월 26일
Thanks for your reply and sorry for the problematic image.
Regarding your comment, what I want is the length that I have specified by RED line in the following image (I have done this funny thing in Paint, so that I can show you what I want, sorry for the mess!)
So, how may I do so now? shall I invert it? (your second code or first code?)
By the way! when I invert the image, will I use any data?
Is there anyway for calculating the perimeter without inverting?
Thanks so much!
Steven
How about just simply doing
totalPerimeter = sum(bwperim(binaryImage));
Steven
Steven 2013년 12월 22일
Thanks again.
I get (naturally!) three wide different values from three different codes.
How can I know which one is correct? (because yet I have no idea of the scales)
Thanks.
Steven
Image Analyst
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개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2013년 12월 22일

편집:

2016년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by