Azzera filtri
Azzera filtri

How to count the number of pixels in each grid ?

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 1 Dic 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

Accedi per commentare.

Più risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 30 Nov 2020
Modificato: KALYAN ACHARJYA il 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!

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by