필터 지우기
필터 지우기

How to count the number of pixels in each grid ?

조회 수: 3 (최근 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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by