I would do I calculate the surface area of an abnormal shape?

1 vue (au cours des 30 derniers jours)
Sohaib Eltayeb
Sohaib Eltayeb le 1 Déc 2022
Commenté : Torsten le 1 Déc 2022
I have a cell (1x12 cell) each one has an traces of the eye ball in different slices. Each slice has an x-coordinates and y-coordinates (first one 242x2 double, second 275x2, etc) I was able to loop over that 1x9 cell and plot each eye ball as seen in the image below.
Now I would like to calculate the surface area of each eye ball and determine which one is the maximum area of all 12 slices.
Here's my code for plotting all slices in the same plot.
%% loading data using cvsROIs function
[cvsROIs] = ReadImageJROI('Q53_OS_Prim_Eyeball_RoiSet.zip');
%% looping over all the data
figure(1)
for i = 1:length(cvsROIs)
%mnCoordinates are the x and y coordinates
g = cvsROIs{1,i}.mnCoordinates();
%nPosition is the number of the slice
slice = cvsROIs{1,i}.nPosition();
str = sprintf('Slice number %.0f',slice);
% plotting all the slices in the same stack
plot(g(:,1),g(:,2))
% reverse to the correct axies position
set(gca,'Ydir','reverse')
title('Plot of the Eyeball for a single slice')
hold on;
%legend(str)
title('Plot of the EyeBall in all the slices')
M = max(g,[],'all');
end
legend('show')

Réponse acceptée

David Hill
David Hill le 1 Déc 2022
pgon(i)=polyshape(g(:,1),g(:,2));
plot(pgon(i));
A(i)=area(pgon(i));
  2 commentaires
Sohaib Eltayeb
Sohaib Eltayeb le 1 Déc 2022
Thank you, David this is great in finding the area. But I am trying to find which nPosition() has the maximum area .
if you look at the for loop, cvsROIs has mnCoordinates and also the nPosition which is slice number. I am intersted in find the slice that gives me the maximum area.
slice = cvsROIs{1,i}.nPosition(); % gives you the slice number in each iteration.
I tried using
maxArea = max(A);
that gave me the maximum value from A but it doesn't really tell me the slice number.
Torsten
Torsten le 1 Déc 2022
"max" has two outputs: the maximum value and the index where the maximum is attained.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 1 Déc 2022
Looks like you've processed an image of an eyeball, got a mask, and then used bwboundaries to get a list of (x,y) coordinates. So there are several ways you can get the area, and will give you slightly different areas because they use different algorithms.
If you have the mask image, you can get the area like this:
eyeballArea = bwarea(mask);
This takes into account the shape of the boundary. For example some pixels on a slanted part may contribute the area of only half a pixel.
Or you can use regionprops
props = regionprops(mask, 'Area');
allAreas = [props.Area]
This way gives a simple pixel count of each connected blob in the image. It's what I use mostly.
Another way is to get the areas from polyarea by getting the boundary of each blob (looks like you have only one). Here's a very well-commented snippet to get all the boundaries, areas, and plot the boundaries over the image in the overlay.
% Plot the borders of all the blobs in the overlay above the original grayscale image
% using the coordinates returned by bwboundaries().
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
imshow(originalImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(mask);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
allAreas(k) = polyarea(x, y);
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
fontSize = 15;
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by