function [img] = reduce_nonlinear(im, template)

new_row = ceil(size(im,1)/size(template,1))+4;
new_col = ceil(size(im,2)/size(template,2))+4;

img = zeros(([new_row new_col]))+255;
wsizey = floor(size(template,1)/2);
wsizex = floor(size(template,2)/2);
crow = 3;
for row = (wsizey+1):size(template,1):(size(im,1)-2*wsizey-1),
  ccol = 3;
  for col = (wsizex+1):size(template,2):(size(im,2)-2*wsizex-1),
    
    patch = im((row-wsizey):(row-wsizey+ size(template,1)-1), (col-wsizex):(col-wsizex+size(template,2)-1));
    if sum(sum(patch==0))>0,
      img(crow, ccol) = 0;
    elseif sum(sum(patch==120))>0,
      img(crow,ccol) = 120;
    end
    ccol=ccol+1;
  end
  crow=crow+1;
end
return;
