How to sum out all the 1 in the bw image?

1 回表示 (過去 30 日間)
Tan Wen Kun
Tan Wen Kun 2015 年 12 月 10 日
コメント済み: DGM 2024 年 10 月 12 日
I got 280x424x3 logical image.
I want to sum out all the 1 in the image. How to do it?
I want to know how many pixel inside the black region in the image.

採用された回答

Stephen23
Stephen23 2015 年 12 月 10 日
編集済み: Stephen23 2015 年 12 月 10 日
This is my answer to your last question. If X is a grayscale RGB image, this will count the white pixels:
idy = all(X,3); % R==G==B
out = sum(idy(:)); % count 1's
Note that you should not store your image as a .jpg file, as this is a lossy format. .png would be more suitable.
Anyway, here is one easy way to count the pixels with values less than 127 ("black"):
>> X = imread('1_2.jpg');
>> Y = X>127;
>> L = sum(Y(:)) % Light
L = 97146
>> D = sum(~Y(:)) % Dark
D = 21574
And the total pixels in both of these is equal to the total pixels in the image:
>> L+D
ans = 118720
>> prod(size(X))
ans = 118720

その他の回答 (1 件)

khan
khan 2015 年 12 月 10 日
use
Total_ones = numel(find(YourMatrix(:)==1)
  1 件のコメント
DGM
DGM 2024 年 10 月 12 日
area = nnz(mask);
is a lot simpler and faster

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by