How to calculate the pixels occured by white color in binary image
17 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Image Analyst
2017-3-22
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 个评论
Asmalina Mohamed Saat
2020-9-19
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
2020-9-19
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.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!