MATLAB: How to know the size of pixel in mm/cm/m if i create randomly distributed circles or rectangulars

area of pixelmrandom number generator

I created my own black filled cirlces and rectangles in white pixel area (say 100×100) … can i determine the area of circle and image in other units like meter or cm or mm ?

Best Answer

As mentioned above, you need a reference for your pixels. This could be for example PPI (pixels per inch) for your monitor, or pixels per cm.
I would personally start with an image instead of using scatter(). You can generate a plain black 1000 x 1000 grayscale image with the following code
A=zeros(1000);
imshow(A); % note that depending on your monitor size imshow() may also scale your image.
The insertShape() function can then be used to insert circles with specified x,y coordinates and radii. See documentation on insertShape() for squares and polygons.
X = 1000.*rand(30,1);
Y = 1000.*rand(30,1);
radii=20.*(ones(length(Y),1));
A=insertShape(A,'FilledCircle',[X Y radii],'Color','white','Opacity',1);
imshow(A)
Now, you could work out the percent area with respect to the total image if you wanted
percent_area=nnz(rgb2gray(A))/1000^2
Note that this does not double the area of overlapping pixels (i.e. where the shapes overlap, the overlapping region is only counted once). Although I suspect the above percent_area might be what you are looking for...?
Again, if you want mm^2, you need to provide a reference of some sort.
Related Question