简体   繁体   中英

Finding out number of pixels in white area in binary image as well as number of pixels of ROI in original image in MATLAB

I have segmented image in which my region of interest (ROI) was white color cotton. Now I want to compare the number of pixels in segmented area ie total number of pixels in white blob in binary image with actual number of pixels of ROI in actual image. How I can do that. Following figure can clear the point. 在此处输入图片说明 在此处输入图片说明

As we can see from original image, my ROI was white color cotton circled in red boundry. When I segmented this image I got binary image as shown. As we can noticed there are some missing areas in binary image as compare to original area. So, I want to count the number of pixels in original image of ROI and number of pixels of white blob in binary image. So that I can calculate difference in actual pixels of ROI and actual segmented number of pixels.

Thank You.

If you wish to not draw the boundaries yourself, you can try this. It might not be as precise as you need, but you might get close to the actual value by tweaking with the thresholding values I used (100 for all 3 channels in this case).

Assume I is your original image. First create the binary mask by thresholding with the RGB values. Then remove all the small objects that don't have at least a 2000 pixel area. Then sum up the pixels of that object.

IT = I(:,:,1) > 100;
IT(I(:,:,2) < 100) = 0;
IT(I(:,:,3) < 100) = 0;
IT = bwareaopen(IT, 2000);
sum(IT(:) > 0)

21380

Resulting image: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM