フィルターのクリア

I have a binary image, how can I count the balck pixels as a group??

2 ビュー (過去 30 日間)
REZA
REZA 2016 年 10 月 30 日
回答済み: Image Analyst 2016 年 10 月 30 日
I process a rgb image to gray to binary and use filters to remove noise and get some specific black areas. Now I want to count the areas. How many are there? How can I do that? can anyone help me?

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 30 日
Add a white border around the entire image. Now use regionprops() and ask for EulerNumber
"Returns a scalar that specifies the number of objects in the region minus the number of holes in those objects. "
The number of objects in the region would be 1 (all of the white part together as you have no isolated white areas), so the number you get out would be negative; take 1 minus the number to get the number of black regions.
Or you could invert the binary matrix. After that there would be a number of different approaches, including, for example, asking regionprops for any simple statistic such as Area, and then just counting the number of outputs you get
NumberOfBlackAreas = length( regionprops( ~YourBinaryMatrix, 'Area' ) );
  2 件のコメント
REZA
REZA 2016 年 10 月 30 日
Hi, thank you for your reply. Can you please explain a little with some code example...As I am new with matlab..
Walter Roberson
Walter Roberson 2016 年 10 月 30 日
cman = imread('cameraman.tif');
YourBinaryImage = cman > 30;
NumberOfBlackAreas = length( regionprops( ~YourBinaryImage, 'Area' ) )

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 30 日
You can get it by inverting your image and calling bwlabel:
[labeledImage, numRegions] = bwlabel(~binaryImage);
No need to call regionprops() just to get the count, though you might want to if you want to measure other things like areas.

Community Treasure Hunt

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

Start Hunting!

Translated by