function bitmap = findRidges2(mat) rows = size(mat,1); cols = size(mat,2); %vals = sort(mat(:)); %index = floor(rows*cols*.95); %maxone = vals(index); %max(vals) %maxone bitmapCols = findRidgesCol2(mat(:,1)); for k=2:cols col = findRidgesCol2(mat(:,k)); bitmapCols = [bitmapCols col]; end [L,NUM] = bwlabeln(bitmapCols); k=1; total = NUM; maxone = 0; for m=1:NUM pts = sum(sum(L==m)); if pts < 50 %10 M = ones(size(L)) - (L==m); L = M .* L; total = total - 1; else avg(k) = sum(sum(mat .* (L==m))) / pts; if avg(k) > maxone maxone=avg(k); indie = m; end k = k + 1; end end for m=1:NUM pts = sum(sum(L==m)); if pts ~= 0 avg = sum(sum(mat .* (L==m))) / pts; if avg < maxone/6 % /2 M = ones(size(L)) - (L==m); L = M .* L; end end end % indie % avg % mean(mean(mat)) % maxone % total %bitmap = (L==indie); bitmap = (L > 0); %bitmap = bitmapCols; % for m=2:rows-1 % for n=2:cols-1 % if bitmapCols(m,n) == 1 % neighborhood = bitmapCols(m-1:m+1,n-1:n+1); % neighbors = sum(sum(neighborhood)); % % if neighbors >= 3 % bitmap(m,n) = 1; % end % end % end % end