count each row white pixels from the bottom to the top

i'm doing car plate localization project. now i wanna count each row white pixels from the bottom to the top. below is my code. thanks for advice.
[code] clc;clear all; % resize input = imread('1.jpg') I = imresize (input, [288 768]); J = rgb2gray(I); L = medfilt2 (J, [5 5]); BW1 = edge(L,'sobel'); [x y]=size(BW1); imtool(BW1);
for i=1:x sumAlongRow = sum (sum (BW1==1));% Gives horizontal "profile." end [/code]

2 comentarios

To format the code, select it and click the {} button, thanks.
ong
ong el 28 de Jul. de 2011
[code]
clc;clear all;
input = imread('1.jpg');
I = imresize (input, [288 768]);
J = rgb2gray(I);
L = medfilt2 (J, [5 5]);
BW1 = edge(L,'sobel');
[x y]=size(BW1);
for
i=1:x sumAlongRow = sum (sum (BW1==1));
end
[/code]

Iniciar sesión para comentar.

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 28 de Jul. de 2011
The loop is unnecessary.
% First element of counts is the last row count:
counts(size(BW,1):-1:1,:) = sum(BW == 1,2);
or you can simply use:
counts = flipud(sum(BW == 1,2));

2 comentarios

ong
ong el 28 de Jul. de 2011
you mean apply like this
for i=1:x
counts = flipud(sum(BW1 == 1,2));
disp('total white color for each row:');disp(i);disp(counts);
end
sorry, i'm fresh learner so i may ask more question
You don't need any loop. Just execute it on BW.
Also, look at the documentation on sum(...,2);

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Jul. de 2011
BW1 is already binary. You don't need to do BW1==1. Just use BW1 directly.

Categorías

Preguntada:

ong
el 28 de Jul. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by