MATLAB: How to calculate the area of this crescent shape

scrollspiral

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

Best Answer

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