function PROCEDURE_CollectContextAtAppearanceLocations_2(objname)
%
%intent:  Rigid object detection was performed using crops
% if we are to show contextual improvement we must sample the context at these locations

ContextRoot = '/cbcl/scratch01/bileschi/EzContext/LayerImgs800_3547_LinSVMSem/';
saveroot = '/cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector';
HelpTextInfo = help('PROCEDURE_CollectContextAtAppearanceLocations_2');
cd /cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector
load('CAfilelist_FilterSS');%-->CAfilelist

if(nargin < 1)
  objname = 'bicycle';
end

AppearanceTemplate = sprintf('AppearanceData_128x128_%s_f*.mat',objname);
AppearanceFNs = dir(AppearanceTemplate);
nParts = length(AppearanceFNs);
fprintf('there are %d appearance parts\n',nParts); 


for i = 1:nParts
   FRACTION_NUM = i
   previdx = -1;
   load(AppearanceFNs(i).name);%-->myBBox, mIdx, y, +++ 
   nSamples = length(y);
   ctxX = zeros(800, nSamples);
   for j = 1:nSamples
      if(mod(j,10)==0)
        fprintf('%d of %d\r',j,nSamples);
      end
      imidx = myIdx(j);
      if(imidx ~= previdx);
         CtxIm = LoadCtxImage(imidx);
      end
      center_xy = BBoxCenter(myBBox(j,:));
      center_xy = CoordinateRespace(center_xy, [960 1280], [60 80]);
      center_xy = round(center_xy);
      ctxX(:,j) = CtxIm(center_xy(2), center_xy(1), :);
   end
   savename = fullfile(saveroot,sprintf('ContextData_128x128_%s_f%.3d.mat',objname,i));
   save(savename,'ctxX','y','HelpTextInfo');
end
 
function LayerImg800 = LoadCtxImage(imidx)
fn = sprintf('/cbcl/scratch01/bileschi/EzContext/LayerImgs800_3547_LinSVMSem/Lay800_%.5d.mat',imidx);
load(fn);
  
