how do I calculate the area of the black pixels?

1 view (last 30 days)
SvenvdB on 25 Jun 2021
Commented: SvenvdB on 25 Jun 2021
I have a pixture and i want to calculate the surface of the black area in the middle. I know the size of the small square's (10x10mm). and the distance between them is 18cm.
I have a script that outputs the amount of black pixels and white pixels but i would like to to output the surface area in milimeters.
Is this possible to do? I dont have much experience with matlab so does anyone have any tips on how to do it if it is possible
black pixels: 873454
white pixels: 2640296

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jun 2021
filename = '';
img = imread(filename);
BW = imbinarize(rgb2gray(img));
format long g
props = regionprops(~BW, 'Area');
sA = sort([props.Area])
sA = 1×5
930 997 1051 1087 92901
mA = mean(sA(1:end-1))
mA =
relA = sA(end)/mA
relA =
small_area = 10*10;
absA = relA * small_area
absA =
The small black squares are not all the same area, so I took the mean() area as being representative.
The large square is 91.4 times larger than the (mean) smaller square
The smaller square is 10x10 = 100 mm^2 so the larger one is 9141.5 mm^2
SvenvdB on 25 Jun 2021
On the normal jpg they are al the same size. but the picture above i took with a camera and thats why the are different. thanks for the explaination, helped alot.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!