function caEdgeFeedback = EdgeFeedback(nStartingLayer,cHS,cMaxFilts,cMinFilts,bUseDotProduct);
% function EdgeFeedback = EdgeFeedback(cHS,cMaxFilts,cMinFilts);
%
% for each layer in cHS, find the sparsest stimulation of the sizse of cHS{1} which could have caused
% it.  
% the length of the cell array of maxfilts/minfilts better == the numlayers in each cHS image.

Verbose = 0;
Scale = nStartingLayer;
if(Verbose)
  fprintf('Beginning scale %d\n',Scale);
end
TopLayer = Scale;
D = cHS{TopLayer};
n=0;
for i = (TopLayer-1):-1:(1)  
  n = n+1;
  if(Verbose)
   fprintf('Beginning Pushback %d of %d\n',n, TopLayer-1);
  end
  A = cHS{i};
  ABar = PushBackOneLayer(A,D,cMaxFilts,cMinFilts,bUseDotProduct);
  D = ABar;
  caEdgeFeedback{i} = ABar;
end

function ABar = PushBackOneLayer(A,D,cMaxFilts,cMinFilts,bUseDotProduct);
ABar = zeros(size(A));
for i = 1:size(cMaxFilts,2) 
  C = imresize(D(:,:,i),[size(A,1),size(A,2)],'bilinear'); % --> Undo Depricate
  %%%B = -maxfilter_arbitrarySupport(-A(:,:,i),cMinFilts{i});
  %%%FeedbackB = -maxfilter_arbitrarySupport(-C,cMaxFilts{i});
  BBar = -maxfilter_arbitrarySupport(-C,cMaxFilts{i});
  % f = find(B == CloseB);
  % BBar = zeros(size(B));
  
  %% BBar = min(B,FeedbackB);
  if(bUseDotProduct)
    ABar(:,:,i) = (A(:,:,i) .* maxfilter_arbitrarySupport(BBar,cMinFilts{i}));
  else
    ABar(:,:,i) = min(A(:,:,i),maxfilter_arbitrarySupport(BBar,cMinFilts{i}));
  end
end

