function [Y,LayrImg] = CombineToyotaDetectionOutputs(Ypyr)
%function [Y,LayrImg] = CombineToyotaDetectionOutputs(Ypyr)
%

if(iscell(Ypyr))
  nScales = length(Ypyr);
  maxSize = size(Ypyr{1});
  LayrImg = zeros(maxSize(1), maxSize(2),nScales) - inf;
  for i = 1:nScales
     LayrImg(:,:,i) = imresize(Ypyr{i},maxSize(1:2),'bilinear');
  end
else
  nScales = size(Ypyr,3);
  maxSize = size(Ypyr(:,:,1));
  LayrImg = Ypyr;
end
BLayrImg = zeros(maxSize(1), maxSize(2),nScales) - inf;
for i = 2:(nScales-1)
   BLayrImg(:,:,i) = LayrImg(:,:,i-1) + LayrImg(:,:,i) + LayrImg(:,:,i+1);
end
Y = max(BLayrImg,[],3);