How to calculate the pixels occured by white color in binary image

29 Ansichten (letzte 30 Tage)
After converting the image to binary image and my primary aim is count the area covered by the white color and the black color in the binary image. For Example, we have performed edge detection on the image and we got an output image in binary image. I want to calculate the area of the edge in the image which are in white.

Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Mär. 2017
To find the white and black pixels:
numWhitePixels = sum(binaryImage(:));
numBlackPixels = sum(~binaryImage(:));
To get the number of perimeter pixels of the white regions
perimImage = bwperim(binaryImage);
numPerimeterPixels = sum(perimImage(:));
An alternate way to get the area of the white is to use bwarea():
% A weighted sum of white pixels that depends on shape of perimeter.
area = bwarea(binaryImage);
  16 Kommentare
Asmalina Mohamed Saat
Asmalina Mohamed Saat am 19 Sep. 2020
okay..thanks
and if I want to calculate the area of white region can I use this coding area = bwarea(numwhitepixel);?? andwhat is the unit of that area?
Image Analyst
Image Analyst am 19 Sep. 2020
You use bwarea() on a binary image, not a scalar number that is the count of how many pixels there are.
% Method 1
area = nnz(binaryImage);
% Method 2
area = bwarea(binaryImage);
The units are pixels. It uses a different algorithm for computing area. See it's documentation. It's not simply a pixel count but weights the edge pixels according to the shape of the boundary locally.
If you want to report the area in real world units like square centimeters, you'll have to get a spatial calibration factor to convert linear pixels to cm, and areas to cm^2. See my attached spatial calibration demo.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 22 Mär. 2017
nnz(TheBinaryImage)
or
sum(TheBinaryImage(:))

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by