function [ map_info ] = get_map_info(pooling, patch_sz, prev_info)

if ~exist('prev_info', 'var')
    prev_cov = 1;
    prev_scale = 1;
else
    map_info = prev_info;
    prev_cov = prev_info.cover;
    prev_scale = prev_info.scale;
end

% Height and width of the new feature map
map_info.height = floor((prev_info.height - patch_sz + 1)/pooling);
map_info.width  = floor((prev_info.width  - patch_sz + 1)/pooling);

% We want to compute the coverage of a pixel in the feature map.
% Consider pooling of 4 and patch size of 8 on a 1D image:
%
% 12345678901234567890
% |__|___|  |
%    |______|
% \  /\  /\  /\  /\  /
%  \/  \/  \/  \/  \/ 
%
% The first feature map element pools from 4 patch responses
% which cover from pixel 1 to pixel (4 + 8 - 1), so  
%       cover_0 = pooling + patch_sz - 1;
%
% At the next layer we will have (pooling + patch_sz - 2) elements
% which each cover scale_{i-1} pixels, and one rightmost element
% wich covers cover_{i-1} elements.
%       cover_i = scale_{i-1} * (pooling + patch_sz - 2) + cover_{i-1};

map_info.cover  = (prev_scale * (pooling + patch_sz - 2)) + prev_cov;
map_info.center = (map_info.cover + 1)/2;
map_info.scale  = prev_scale * pooling;

% We want to be able to compute raw pixel coordinate x given
% feature map coordinate x' and vice versa.
% 
% Given x' we want to compute the x closest to the center of x':
% x = scale*(x' - 1) + center;
% 
% Given x' we want to compute its cover on the original image:
% x_min = scale*(x' - 1) + 1;
% x_max = scale*(x' - 1) + cover;
%
% Given x we want to compute the x' whose center is closest to x:
% x' = round( (x - center)/scale + 1 ) ;
% x' = max(x',1);
% x' = min(x',correctsize);

end

