Hi Folks,
So, I want to calculate the perimeter of an object. I have posted an image to this question. I wrote a short script - which I found on Mathworks - to trace the object of interest with a green trace. I was wondering if I can calculate the perimeter of this object. The perimeter measurement would be acquired first in number of pixels, and then I would convert that number into a physical SI measurement using a value I have written down.
My question is... How would I go about this? Also, would tracing the perimeter of the object, as I have done, help? Or, does tracing just serve to be a visual aid?
Here is the figure. The green is obviously the trace of the perimeter. In advance, thank you for reading through this!

 채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 20일

0 개 추천

Go back to the mask without the green traced in, and use regionprops() and ask for Perimeter

댓글 수: 5

Sean Farrell
Sean Farrell 2016년 10월 20일
Okay, thanks! I just took a look at the function in MatLab, and it seems pretty sweet. How about if I am dealing with this image, shown below? How would I account for numerous objects? Pay no mind to the green trace; that was just me fiddling.
Walter Roberson
Walter Roberson 2016년 10월 20일
regionprops can handle multiple objects. But you need to clarify whether the areas that are thinly connected should be treated as one blob or should have their bounds broken and treated as multiple blobs.
Sean Farrell
Sean Farrell 2016년 10월 20일
Okay, thank you sir. I might come back to this thread to drop a quick question if I can't figure out how to apply the function to multiple objects. Thanks again!
Sean Farrell
Sean Farrell 2016년 10월 22일
If I have multiple objects, as in the image shown above, how do I know what perimeter belongs to which object?
Image Analyst
Image Analyst 2016년 10월 22일
편집: Image Analyst 2016년 10월 22일
regionprops can handle multiple regions by returning a structure array:
props = regionprops(labeledImage, 'Area', 'Perimeter');
allAreas = [props.Area];
allPerimeters = [props.Perimeter];
To get the outlines as an array of (x,y) coordinates, use bwboundaries() and then use plot() to plot them all over the original image, like this snippet:
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the regions on the original grayscale image using the coordinates returned by bwboundaries.
imshow(originalImage);
title('Outlines, from bwboundaries()', 'FontSize', captionFontSize);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

nikhil agrawal
nikhil agrawal 2016년 10월 20일

0 개 추천

Go back to the mask without the green traced in and use regionprops() and Ask for Perimeter.

질문:

2016년 10월 20일

편집:

2016년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by