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 Comments

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

Sign in to comment.

 Accepted Answer

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 Comments

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);

Sign in to comment.

More Answers (1)

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

Asked:

ong
on 28 Jul 2011

Community Treasure Hunt

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

Start Hunting!