function [a,b]=maxline(m,val,w);
% approximate lines to image point indicated by the value val. 
% The lines must be row oriented. the row gap may be of size w.
% m: image
% val : pixel values to be approminated.
% w   : row gap
% a,b : array with line parameters : row= a* column + b
%
[r,c]= size(m);
pos=1; gat=0;
N=0; sx=0; sy=0; sxx=0; sxy=0;
a(1)=0;
b(1)=0;
	for i1=1:r
	gat=gat +1;
		for j1=1:c
		if m(i1,j1) == val
			gat=0;
			sx=sx + j1;
			sxx=sxx + j1*j1;
			sxy=sxy + i1*j1;
			sy=sy + i1;
			N=N+1;
		end;
		end;
	if (gat> w) & ~(N==0)
		noem=N*sxx-sx*sx;
		if ~(noem==0)
			a(pos)=(N*sxy-sx*sy)/noem;
			b(pos)=(sxx*sy-sx*sxy)/noem;
		else
			a(pos)=0;
			b(pos)=sy/N;
		end
		N=0; gat=0;
		sx=0; sy=0; sxx=0; sxy=0;
		pos=pos+1;
	end;

	end;
end;



