%SCRIPT_GrayscaleObjectsInTestImages
%
%intent:  detect object named objname in images 1:300 and record in 
%/cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector/GrayscaleAppObjDet/objname
%clear all;

objs{1} = 'car';
objs{2} = 'pedestrian';
objs{3} = 'bicycle';

for iObj = 1:3
 objname = objs{iObj};

startsize = [240 320];
cmd = sprintf('load /cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector/GSBoostModel_%s.mat',objname);
eval(cmd);%-->GSBoostModel
SaveRoot = sprintf('/cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector/GrayscaleAppObjDet/%s',objname);
seedrand;
load CAFileList_FilterSS;
p = randperm(300);
for i = p
   fprintf('beginning %s detection on %d\n',objname, i);
   savename = fullfile(SaveRoot,sprintf('GrayscaleDet_%.5d.mat',i));
   if(exist(savename))
     continue;
   end
   im = imread(CAfilelist{i}.imagename);
   im = rgb2gray(im);
   n = 0;
   sizeratio= 1/(2).^(1/4)
   s = startsize;
   while(all(s > [32 32])) 
      n = n+1;
      s = floor(startsize * (sizeratio^n));
      imx = imresize(im,s);
      [yEmpl{n},yEmp{n}] = WindowedObjectDetection(GSBoostModel, [32 32], imx,1);
      s = floor(startsize * (sizeratio^(n+1)));
   end
   nLayers = length(yEmpl);
   clear caYLayr;
   for i = 1:nLayers
      caYLayr{1}(:,:,i) = imresize(yEmp{i},size(yEmp{1}),'bilinear');
   end
   DL = PeakDetection_LocalSuppression(caYLayr);
   save(savename,'caYLayr','DL');
end   

end
