Filter löschen
Filter löschen

How to count the number of pixels in each grid ?

3 Ansichten (letzte 30 Tage)
Suyog Pathare
Suyog Pathare am 29 Nov. 2020
Kommentiert: Suyog Pathare am 3 Dez. 2020
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Nov. 2020
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 Kommentare
Image Analyst
Image Analyst am 1 Dez. 2020
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 am 3 Dez. 2020
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 30 Nov. 2020
Bearbeitet: KALYAN ACHARJYA am 30 Nov. 2020
"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!

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by