get_subwindow

PURPOSE ^

GET_SUBWINDOW

SYNOPSIS ^

function out = get_subwindow(im, pos, sz)

DESCRIPTION ^

GET_SUBWINDOW  

 GET_SUBWINDOWwith Obtain sub-window from image, replication-padding.
   Returns sub-window of image IM centered at POS ([y, x] coordinates),
   with size SZ ([height, width]). If any pixels are outside of the image,
   they will replicate the values at the borders. 

   See also: TARGETSEARCHDSKCF, SINGLEFRAMEDSKCF,
   SINGLEFRAMEDSKCF_OCCLUDER

   This function has been inserted in the DS-KCF matlab library from the
   KCF library released by

   Joao F. Henriques, 2014
   http://www.isr.uc.pt/~henriques/

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out = get_subwindow(im, pos, sz)
0002 %GET_SUBWINDOW
0003 %
0004 % GET_SUBWINDOWwith Obtain sub-window from image, replication-padding.
0005 %   Returns sub-window of image IM centered at POS ([y, x] coordinates),
0006 %   with size SZ ([height, width]). If any pixels are outside of the image,
0007 %   they will replicate the values at the borders.
0008 %
0009 %   See also: TARGETSEARCHDSKCF, SINGLEFRAMEDSKCF,
0010 %   SINGLEFRAMEDSKCF_OCCLUDER
0011 %
0012 %   This function has been inserted in the DS-KCF matlab library from the
0013 %   KCF library released by
0014 %
0015 %   Joao F. Henriques, 2014
0016 %   http://www.isr.uc.pt/~henriques/
0017 %
0018 %
0019 
0020     if isscalar(sz),  %square sub-window
0021         sz = [sz, sz];
0022     end
0023     
0024     xs = floor(pos(2)) + (1:sz(2)) - floor(sz(2)/2);
0025     ys = floor(pos(1)) + (1:sz(1)) - floor(sz(1)/2);
0026     
0027     %check for out-of-bounds coordinates, and set them to the values at
0028     %the borders
0029     xs(xs < 1) = 1;
0030     ys(ys < 1) = 1;
0031     xs(xs > size(im,2)) = size(im,2);
0032     ys(ys > size(im,1)) = size(im,1);
0033     
0034     %extract image
0035     out = im(ys, xs, :);
0036 
0037 end
0038

Generated on Thu 24-Nov-2016 18:03:21 by m2html © 2005