function out=gate(im)
[r,c]=size(im);
out(r,c)=0;
for j=1:c
	i=r;
	while (i>1 & im(i,j)==0)
	i=i-1;
	end;
	edge(j)=i+1;
	out(i+1,j)=255;
end;
nr=1;
compb(nr)=1;
for j=2:c
	if abs(edge(j)-edge(j-1)) > 3
		compl(nr)=j-1-compb(nr);
		nr=nr+1;
		compb(nr)=j;
	end;
	compl(nr)=c-compb(nr);
end;
compb
compl
end;
