Borrar filtros
Borrar filtros

How to count the number of pixels in each grid ?

3 visualizaciones (últimos 30 días)
Suyog Pathare
Suyog Pathare el 29 de Nov. de 2020
Comentada: Suyog Pathare el 3 de Dic. de 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.

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Nov. de 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 comentarios
Image Analyst
Image Analyst el 1 de Dic. de 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 el 3 de Dic. de 2020
Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Nov. de 2020
Editada: KALYAN ACHARJYA el 30 de Nov. de 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!

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by