MATLAB: Count each row white pixels from the bottom to the top

image analysisimage processing

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]

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