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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 7월 28일
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

ong
ong 2011년 7월 28일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2011년 7월 30일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

질문:

ong
2011년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by