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 commentaires

To format the code, select it and click the {} button, thanks.
ong
ong le 28 Juil 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]

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

ong
ong le 28 Juil 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);

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 30 Juil 2011

0 votes

BW1 is already binary. You don't need to do BW1==1. Just use BW1 directly.

Community Treasure Hunt

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

Start Hunting!

Translated by