function result = image_extract(image, location, box_size)
%  function result = image_extract(image, location, size)
%
%  Extract a box of given size from the given location in an image.
%
%  TODO: need to add boundary conditions
%
% $Id$

start = round(location - box_size/2);
stop = start + box_size - [1,1];

image_size = size(image);
start(start < 1) = 1;

if (stop(1) > image_size(1))
    stop(1) = image_size(1);
end

if (stop(2) > image_size(2))
    stop(2) = image_size(2);
end

result = image(start(1):stop(1),start(2):stop(2));

result = pad(result, box_size, 0);