how to find the number of pixels in the white region of a binary image

조회 수: 15 (최근 30일)
Rah Ul
Rah Ul 2022년 7월 3일
답변: Image Analyst 2022년 7월 3일
I want to get the number of pixels o the white area in the given binary image. is there any code available to know tha same. The ultimate need is to find the area of the region by multiplying number of pixels with area of one pixel

답변 (2개)

Raghav
Raghav 2022년 7월 3일
편집: Jan 2022년 7월 3일
As white pixels have a value=1 (and black pixels' value=0), doing sum of pixel values can return the total number of white pixels in the binary image. If Image is stored in "Im", you can write the expression:
WhiteNum=sum(Im(:));
If you want to find the area of object formed by white pixels, use the function - bwarea().
To understand more about bwarea(), refer to the link that I am attaching below:

Image Analyst
Image Analyst 2022년 7월 3일
You can use nnz or bwarea
Note they give different counts. nnx is strictly a count of the number of pixels. bwarea weights the counts by the shape of the boundary.
binaryImage = [0,1;1,1]
binaryImage = 2×2
0 1 1 1
numWhite = nnz(binaryImage)
numWhite = 3
area = bwarea(binaryImage)
area = 3.1250

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by