
function Combined=kproc3(inp,blksize,filtsize,fact1,fact2,type)
% this function finds the separation between bands, based upon max-min 
% filtering.
% parameters:
% inp : input image
% res : result image inwhich the separation pixels are 1
% blksize : the bloksize in which the image is divided up and in which
% 	separation rows are found
% filtsize : filtersize of the smoothing (2* filtsize+1)
% fact : local maximum/minimum definition.
% type = 1 lane separators; type = not 1 : middle of lanes
tic;
stp=20; % defined by max angle +/- 3 graden. 
[rg,cg]=size(inp);

Res = zeros(rg,cg);

Combined = zeros(blksize+1,1);

filtalg=filtsize/2;
if (filtalg <1) filt =1; end;

ib=1;
is=blksize;
offs=0;
prehis=zeros(1,cg);
block = 1;
if (type ~=1) type = -1; end;

while ib<rg	
ib
ie=min(ib+is-1,rg);
    new_entry = zeros(blksize+1,cg);
    count1 = 0;

	g=inp(ib:ie,:)';	% tranpose matrix

	% max-min filter across bands
	p=maxfil(g,filtsize)-minfil(g,filtsize);

	% max-min filter along bands
	q=maxfil(g',filtalg)-minfil(g',filtalg);
	p=p-q'/2;
	%imshow(p);

	% calculate histograms (his) and correlate them to previous ones
	% to find the displacements (ofar) (pseudo hough)

	his=prehis/4;
	[his,ofar]=dyhgh1(p,stp,prehis);
	hispre=his; % current histogram becomes previous
	totmx=max(his);
	totmn=min(his);

	% find the maxima or minima in the histograms
	
	s=maxpos(his',fact1);

	% throw out small maxima and compute lane positions

	for jo=1:cg;
		if (s(jo) == 1) & (his(jo) < fact2*totmx) s(jo)=0; end;
		%if (s(jo) ==-1) & (his(jo) > fact2*totmn) s(jo)=0; end;	
		if (s(jo) == type) 
			count1 = count1 + 1;
			k=1;
	    		new_entry(1,count1) = block;
			for io=(ib:ie);
				new_entry(k+1,count1) = jo+ofar(k);
				k=k+1;
			end
		end
    	end

    Combined = [Combined,new_entry(:,1:count1)];
    block = block +1;

    toc
    ib=ib+is;		% next part
end;

[n,m] = size(Combined);
Combined = Combined(:,2:m);

end;

