function [output] = capture(input,top_left,capture_size,size)

factor = capture_size/size;
output = zeros(size);

for i=0:size-1
   for j=0:size-1
       
       i_front = ceil(top_left(1)+i*factor);
       i_back = floor(top_left(1)+(i+1)*factor);
       j_front = ceil(top_left(2)+j*factor);
       j_back = floor(top_left(2)+(j+1)*factor);

       A = ones(i_back-i_front+3,j_back-j_front+3);
       [m n] = size(A);
       A(1,:) = A(1,:)*(i_front-top_left(1)-i*factor);
       A(m,:) = A(m,:)*(top_left(1)+(i+1)*factor-i_back);
       A(:,1) = A(:,1)*(j_front-top_left(2)-j*factor);
       A(:,n) = A(:,n)*(top_left(2)+(j+1)*factor-j_back);
       
       output(i+1,j+1) = sum(sum(input(i_front-1:i_back+1, ...
                         j_front-1:j_back+1).* A ))/sum(sum(A));
   end
end  

output = round(output);
