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

	end;
end;
nr=1;
compb(nr)=1;
for j=2:c
	if abs(edge(j,1)-edge(j-1,1)) > 3
		compl(nr)=j-1-compb(nr);
		nr=nr+1;
		compb(nr)=j;
	end;
	compl(nr)=c-compb(nr);
end;
compb
compl
end;
end;
