How to count the number of pixels in each grid ?

15 ビュー (過去 30 日間)
Suyog Pathare
Suyog Pathare 2020 年 11 月 29 日
コメント済み: Suyog Pathare 2020 年 12 月 3 日
I have burned the lines into the image and now I want I want to count the number of pixels in each grid. It is a binary image.

採用された回答

Image Analyst
Image Analyst 2020 年 11 月 30 日
Try this:
[rows, columns] = size(binaryImage);
x = round(linspace(1, columns+1, 11)); % Divide into 10 zones.
y = round(linspace(1, rows+1, 3)); % Divide into 2 zones.
for r = 1 : length(y) - 1
for c = 1 : length(x) - 1
row1 = y(r);
row2 = y(r+1) - 1;
col1 = x(c);
col2 = x(c+1) - 1;
pixelCount(r, c) = nnz(binaryImage(row1:row2, col1:col2))
end
end
Or you could use blockproc(). Demos attached.
  4 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 1 日
You can call xline() and yline():
grayImage = imread('CameraMan.tif');
imshow(grayImage, []);
binaryImage = imbinarize(grayImage);
imshow(binaryImage);
[rows, columns] = size(binaryImage);
x = round(linspace(1, columns+1, 11)); % Divide into 10 zones.
y = round(linspace(1, rows+1, 3)); % Divide into 2 zones.
for r = 1 : length(y) - 1
row1 = y(r);
row2 = y(r+1) - 1;
yline(row1, 'Color', 'r');
for c = 1 : length(x) - 1
col1 = x(c);
col2 = x(c+1) - 1;
pixelCount(r, c) = nnz(binaryImage(row1:row2, col1:col2));
xline(col1, 'Color', 'r');
end
end
Suyog Pathare
Suyog Pathare 2020 年 12 月 3 日
Thank you!

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

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 11 月 30 日
編集済み: KALYAN ACHARJYA 2020 年 11 月 30 日
"I want I want to count the number of pixels in each grid"
As I answered your previous question, assuming you could use the grid number based on how to split the image.
Read the respective grid,then add the all ones in the grid
pixel_counts=sum(grid(:))
This way:
for i=1:..
data=image(graid_i_indices); % Just an Example
pixel_num(i)=sum(data(:));
end
Hope it helps!

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by