How do I calculate the area of this crescent shape?
3 views (last 30 days)
Show older comments
Hi all,
I am trying to calculate the area of this crescent shape attached in the image here. My attempt was to use the polyarea function in matlab to compute the area for the outer and inner coils and subtract them. Is this correct? Please provide your inputs. If any better alternates are available, kindly suggest.
Thanks Arun
0 Comments
Accepted Answer
Image Analyst
on 6 Feb 2016
Edited: Image Analyst
on 6 Feb 2016
Here are three different ways of getting an area. The areas are different because of the different ways they define area. What's your definition?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
[grayImage, map] = imread('crescent.gif');
subplot(2,1,1);
imshow(grayImage, []);
colormap(map);
colorbar;
axis on;
title('Original GIF', 'fontSize', fontSize);
binaryImage = grayImage == 1;
binaryImage = imclearborder(binaryImage);
subplot(2,1,2);
imshow(binaryImage);
title('Binary Image', 'fontSize', fontSize);
% Measure the area from bwarea
baArea = bwarea(binaryImage)
% Measure the area via regionprops
measurements = regionprops(bwlabel(binaryImage), 'Area');
rpArea = measurements.Area
% Measure the area via polyarea
boundaries = bwboundaries(binaryImage);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
pArea = polyarea(x, y)
message = sprintf('The area from bwarea() = %.2f\nThe area from regionprops = %.2f\nThe area from polyarea() = %.2f', ...
baArea, rpArea, pArea);
fprintf('%s\n', message);
uiwait(helpdlg(message));
Results in command window:
The area from bwarea() = 41475.63
The area from regionprops = 41418.00
The area from polyarea() = 40801.50
4 Comments
Image Analyst
on 6 Feb 2016
Try it and see. I believe polyarea expects the points to be in order around the perimeter and if they are not on adjacent pixels, that does not matter. The vertices of the polygon can be anywhere because it's done analytically (using vertex coordinates), not on an image. The fact that your vertices lie on image pixels doesn't matter to it at all.
More Answers (2)
Image Analyst
on 5 Feb 2016
You could if you call bwboundaries first to get the coordinates of the outline. You could also call imclearborder() followed by bwlabel() and regionprops().
0 Comments
John D'Errico
on 5 Feb 2016
Edited: John D'Errico
on 5 Feb 2016
Basic calc?
1. Convert to polar coordinates, centered around the "interior" circle.
2. Find the intersection points between the two circular arcs.
3. Do the integration as the difference between the two arcs. Don't forget that in polar coordinates, the differential element has that r term in it. The integration might be done symbolically, or using integral to do it numerically.
Alternatively, you could do the integration as a Monte Carlo integration. Not terribly accurate, but almost trivially easy to do.
Finally, if you want an approximate solution that is also trivially easy, generate the domain as a polygon, then use polyarea.
2 Comments
See Also
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!