how to calculate the area of each bin of intersection of a circle and mesh grid?

6 views (last 30 days)
I have divided a circle of D=16mm into a grid of 7X7. (8 vertical lines by 8 horizontal lines)
How can I estimate the area of each bin which is enclosed in the circle?
grid layout:
bin size = 16mm/7

Accepted Answer

Image Analyst
Image Analyst on 2 Jun 2023
Try this:
% Demo by Image Analyst to separate point sets using the convex hull.
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 short g;
format compact;
fontSize = 16;
markerSize = 16;
% https://matlab.fandom.com/wiki/FAQ#How_do_I_create_a_circle?
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 1600;
imageSizeY = 1600;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 800;
centerY = 800;
radius = 800;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
subplot(2, 2, 1);
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
axis('on', 'image')
% Now chop it up into 7 by 7 by drawing black lines through it.
blackRows = round(linspace(1, 1600, 8))
img = circlePixels; % Make a copy.
for k = 1 : length(blackRows)
thisRow = blackRows(k);
img(thisRow, :) = false;
img(:, thisRow) = false;
end
% Now, display it.
subplot(2, 2, 2);
imshow(img) ;
title('Chopped into 7x7 grid');
axis('on', 'image')
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(img, 4);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
hFig = figure;
imshow(coloredLabelsImage);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, 'Area', 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
% Go along each blob showing the area
cmPerPixel = 16 / 1600
for k = 1 : numel(blobMeasurements)
thisArea = blobMeasurements(k).Area * cmPerPixel^2; % In calibrated units, not pixels.
xt = blobMeasurements(k).Centroid(1);
yt = blobMeasurements(k).Centroid(2);
str = sprintf('Area=\n%.2f', thisArea);
text(xt, yt, str, 'Color','w', 'FontSize',10,'FontWeight','bold','HorizontalAlignment','center','VerticalAlignment','middle')
end
hFig = gcf;
hFig.WindowState = 'maximized';
Areas are rough estimates because the image is discrete/digitized.

More Answers (2)

Image Analyst
Image Analyst on 31 May 2023
Is that 7 mm by 7 mm? Or pixels? If pixels you need to know how many pixels are in a mm.
If you want individual areas of each "bin", then it depends on how the grid lies in the circle.
viscircles([8, 8], 8);
grid on;
xticks(0:7:16)
yticks(0:7:16);
axis equal
% A rough estimate of the average area
aveArea = pi*8^2 / 8
aveArea = 25.1327
but again, the number of "bins" inside the circle depends on exactly how your grid is lying in the circle. There could just as easily be 4 more bins (total of 12) if the circle above were shifted down and to the left a little bit.
  3 Comments
Image Analyst
Image Analyst on 31 May 2023
It's easy if you have a digital image and knowledge of where the gridlines are. Do you have that? If so, attach the image and let us know what line halfway between rows and columns are the dividing gridlines.
If not, it's a mathematical/geometrical computation. Maybe it could be done by the Symbolic Toolbox but I don't know how. Do you have that toolbox?
Ham Man
Ham Man on 2 Jun 2023
Edited: Ham Man on 2 Jun 2023
this is my 7X7 grid pattern inside the circle of radius=8mm. I want to roughly estimate each grid area inside the circle.

Sign in to comment.


Matt J
Matt J on 2 Jun 2023
Edited: Matt J on 2 Jun 2023
The efficient way would be to first eliminate the grid squares which are wholly inside or outside the circle, which you can determine by testing whether the vertices of a square are all inside/outside the circle.
Once you've narrowed the computation down to the squares straddling the circumference of the circle, you can use polyshape methods to compute intersection area, e.g.,
circle=nsidedpoly(1000); %circular polyshape
squares=[nsidedpoly(4,'Center',[0,1]), nsidedpoly(4,'Center',[0,-1.2])]; %two squares
Areas =area(intersect(circle,squares))
Areas = 1×2
0.8712 0.5883
plot([circle,squares]); axis equal

Tags

Community Treasure Hunt

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

Start Hunting!