1
votes

If I have an arbitrary shape (attached is a really simple mock up), how would I estimate the area of the enclosed surface in Matlab. To get some random points along the curve, I used the ginput command to get a rough estimate of the curve, with unequal spacing between the points. I want to get an estimate of the area, but I believe the trapz command would overestimate the area due to the overlap (Please correct me if I am wrong here). Is there a more accurate way to obtain the area?

Thanks! enter image description here

enter image description here

1
How did you create the shape?NKN
What data do you have? trapz can be used with a good precision too.NKN
@NKN I just created a random drawing as an example. Wouldn't trapz overestimate the area?Cyrus

1 Answers

0
votes

Well, you didn't really give enough info to solve the problem entirely, but here's one approach you can take to find the boundary automatically in order to calculate the area:

% Get image and convert to logical mask
img = ~im2bw(imread('polyarea.jpg'));

% Fill the hole
img = imfill(img,'holes');

% Get boundary
b = bwboundaries(img);

% Approximate area of boundary
area = polyarea(b{1}(:,1), b{1}(:,2));

% Print area
disp(['Area: ' num2str(area)]); 

imshow(img);
hold on;
plot(b{1}(:,2),b{1}(:,1),'go');

The idea is you have an input, you form a logical mask, get the boundary of the mask, and then you can approximate the area enclosed by the boundary by using polyarea.

The output is:

enter image description here

Area: 228003

Additionally, you could also use regionprops(img,'Area') which outputs:

ans = 

    Area: 229154