function [Q] = Q_RL(I, phi) % % Written by: % -- % John L. Weatherwax 2005-08-04 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % % Epage % %----- [di,dj] = phi_to_xy_increment(phi); % Make sure that the pixels of I have values that are indexed from 1,2,...N_g this way we can use MATLAB one based indexing uElts = unique( I(:) ); N_g = length(uElts); Icp = zeros(size(I)); for ii=1:N_g inds = find( I(:)==uElts(ii) ); Icp(inds) = ii; end I = Icp; [M,N] = size(I); N_r = max(M,N); Q = zeros(N_g,N_r); for ii=1:M % row index for jj=1:N % column index Iij = I(ii,jj); % Determine if this pixel already in a run... d = -1; % try to step backwards ii_new = ii+di*d; in_I_Range = (ii_new > 0) && (ii_new < M+1); jj_new = jj+dj*d; in_J_Range = (jj_new > 0) && (jj_new < N+1); if( in_I_Range && in_J_Range && (Iij==I(ii_new,jj_new)) ) pixel_already_in_a_run = 1; else pixel_already_in_a_run = 0; end % find the longest run length starting at (ii,jj) and going in direction phi: % mrl = max_run_length_phi(I, ii,jj, phi); if( ~pixel_already_in_a_run ) Q(Iij,mrl+1) = Q(Iij,mrl+1) + 1; end end end