function box=findbox(aimg,cut,bd,sm)

if(~exist('cut','var') || isempty(cut))
	cut=.5;
end
if(~exist('bd','var') || isempty(bd))
	bd=0;
end
if(~exist('sm','var') || isempty(sm))
	sm=15;
end

sx=conv2(mean(aimg,2),ones(sm,1),'same')/sm;
sy=conv2(mean(aimg),ones(1,sm),'same')/sm;

sx=sx/max(sx(:));
sy=sy/max(sy(:));

x1=find(diff(sx>cut)==1);
x2=find(diff(sx>cut)==-1);
y1=find(diff(sy>cut)==1);
y2=find(diff(sy>cut)==-1);

x1=4*fix(x1(1)/4);
x2=4*fix(x2(end)/4)+3;
y1=4*fix(y1(1)/4);
y2=4*fix(y2(end)/4)+3;

box=[x1+bd x2-bd y1+bd y2-bd];



