Is there any way to get the pixel counts of the segmented image using graphcut

1 回表示 (過去 30 日間)
andhavarapu lokesh
andhavarapu lokesh 2017 年 2 月 18 日
コメント済み: Walter Roberson 2017 年 2 月 18 日
I am using graphcut matlabs
Ncut = (graphcuts(bad3,3,50))
method to segment grayscale image. Is there any way to get the pixel counts? I am getting the segmented image as binary. How to convert the binary image to grayscale and get the pixel count of the segmented grayscale image

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 18 日
nnz(Ncut .* bad3)
nnz((~Ncut) .* bad3)
  3 件のコメント
andhavarapu lokesh
andhavarapu lokesh 2017 年 2 月 18 日
>> nnz((~Ncut).* bad3); Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
Walter Roberson
Walter Roberson 2017 年 2 月 18 日
"n = nnz(X) returns the number of nonzero elements in matrix X."
I presumed here that when you asked for "pixel counts" of a grayscale matrix that you were interested in the number of non-zero grayscale pixels. If you just wanted to know how many entries were there regardless of whether they are 0 or not, then
nnz(Ncut)
nnz(~Ncut)
Another way of writing nnz(Ncut) would be
sum(Ncut(:))
since each entry in Ncut is binary (0 or 1), this counts the number of non-zero entries, which is the same thing nnz does except nnz would be expected to be faster.

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

Community Treasure Hunt

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

Start Hunting!

Translated by