how to calculate the area of the black color and the white color
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Greetings
Please I need help on how to calculate the area of black circles in the following
image
I have a code that generates a random scattered circles and I need to know how much area this circles take from the full given area 100*100
0 Kommentare
Antworten (1)
Ayush
am 23 Okt. 2024
Hi,
To calculate the area of black circles, ensure that the image is in binary format, i.e., the circles are black (0) and the background is white (1). Divide the number of black pixels by the total number of pixels (10,000 for a 100x100 image) to get the fraction of the area occupied by the circles. Refer to an example code below for better understanding:
% Generate or load your binary image with black circles
image = imread('your_image.png'); % Replace with your image generation code
% Convert to binary if necessary
binaryImage = imbinarize(image);
% Invert if circles are white
binaryImage = ~binaryImage;
% Calculate area of black circles using nnz
blackPixels = nnz(~binaryImage); % Count black pixels
totalPixels = numel(binaryImage);
circleAreaPercentage = (blackPixels / totalPixels) * 100;
% Display the result
fprintf('The area occupied by the black circles is: %.2f%%\n', circleAreaPercentage);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!