Home > slowness_model > imgsequence.m

imgsequence

PURPOSE ^

IMGSEQUENCE returns a random image sequence.

SYNOPSIS ^

function [DATA,x_signal,y_signal,rt_signal,zm_signal]=imgsequence(im, h, w, nframes, trrg, trfact, rtfact, zmrg,zmfact)

DESCRIPTION ^

 IMGSEQUENCE returns a random image sequence.

   [DATA] = IMG_SEQUENCE(IM, H,W, NFRAMES, ...
                         TRRG,TRFACT, RTFACT, ZMRG,ZMFACT)

   Create an image sequence of NFRAMES frames of size H x W pixels out
   of the image IM. The sequence is created by choosing an initial
   position at random, cutting a square window and moving it around by
   translation, rotation, and zoom.

   Translation, rotation and zoom are created by the function
   RANDOM_SIGNAL, which returns a random signal that varies smoothly in
   time. The amount of variation in time is controlled by the integer
   numbers TRFACT, RTFACT, and ZMFACT (the higher they are, the faster it
   varies). If one of this arguments is set to zero, the corresponding
   transformation is not performed. TRRG is the maximal distance from the
   initial random point reached by translation. ZMRG is a list of length 2
   that gives the minimum and the maximum possible magnification reached by
   zoom.

   [DATA,X_SIGNAL,Y_SIGNAL,RT_SIGNAL,ZM_SIGNAL]=IMGSEQUENCE(...) returns
   the position signals for the x and y coordinates, the rotation signal
   and the zoom signal. This is sometimes useful to collect statistics
   on the transformations.

   See also RANDOM_SIGNAL.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [DATA,x_signal,y_signal,rt_signal,zm_signal]=imgsequence(im, h, w, nframes, trrg, trfact, rtfact, zmrg,zmfact)
0002 % IMGSEQUENCE returns a random image sequence.
0003 %
0004 %   [DATA] = IMG_SEQUENCE(IM, H,W, NFRAMES, ...
0005 %                         TRRG,TRFACT, RTFACT, ZMRG,ZMFACT)
0006 %
0007 %   Create an image sequence of NFRAMES frames of size H x W pixels out
0008 %   of the image IM. The sequence is created by choosing an initial
0009 %   position at random, cutting a square window and moving it around by
0010 %   translation, rotation, and zoom.
0011 %
0012 %   Translation, rotation and zoom are created by the function
0013 %   RANDOM_SIGNAL, which returns a random signal that varies smoothly in
0014 %   time. The amount of variation in time is controlled by the integer
0015 %   numbers TRFACT, RTFACT, and ZMFACT (the higher they are, the faster it
0016 %   varies). If one of this arguments is set to zero, the corresponding
0017 %   transformation is not performed. TRRG is the maximal distance from the
0018 %   initial random point reached by translation. ZMRG is a list of length 2
0019 %   that gives the minimum and the maximum possible magnification reached by
0020 %   zoom.
0021 %
0022 %   [DATA,X_SIGNAL,Y_SIGNAL,RT_SIGNAL,ZM_SIGNAL]=IMGSEQUENCE(...) returns
0023 %   the position signals for the x and y coordinates, the rotation signal
0024 %   and the zoom signal. This is sometimes useful to collect statistics
0025 %   on the transformations.
0026 %
0027 %   See also RANDOM_SIGNAL.
0028     
0029     
0030 % ver 3.0
0031   
0032   % size of the image
0033   sz=[size(im,1) size(im,2)];
0034   
0035   % repeat until the whole sequence lies inside the image
0036   repeat=1;
0037   while repeat,
0038     repeat=0;
0039 
0040     %% create translation signal (center of the patch)
0041     % random initial position (keep a margin of 3*w along the borders)
0042     x0=floor(rand(1,2).*(sz-6*w))+3*w;
0043     % random translation signal (if trfact==0, no translation)
0044     if trfact==0,
0045       x_signal=zeros(nframes,1)+x0(2);
0046       y_signal=zeros(nframes,1)+x0(1);
0047     else,
0048       x_signal=random_signal(nframes, trfact, -trrg, trrg)+x0(2);
0049       y_signal=random_signal(nframes, trfact, -trrg, trrg)+x0(1);
0050     end
0051     
0052     % create rotation signal (if rrfact==0, no rotation)
0053     if rtfact==0,
0054       rt_signal=zeros(nframes,1);
0055     else,
0056       rt_signal=random_signal(nframes, rtfact, 0, 2*pi);
0057     end
0058   
0059     % create zoom signal (if zmfact==0, no zoom)
0060     if zmfact==0,
0061       zm_signal=ones(nframes,1);
0062     else,
0063       zm_signal=random_signal(nframes, zmfact, zmrg(1), zmrg(2));
0064     end
0065     
0066     % allocate space for the sequence
0067     DATA=zeros(nframes,h*w);
0068       
0069     % loop over all frames
0070     for t=1:nframes,
0071       %%%% translation
0072       % current position
0073       x=[x_signal(t);y_signal(t)];
0074     
0075       %%%% zoom
0076       % compute the corners of the window after zoom
0077       xi(1)=x(1)-zm_signal(t)*w/2;
0078       xx(1)=x(1)+zm_signal(t)*w/2;
0079       xi(2)=x(2)-zm_signal(t)*h/2;
0080       xx(2)=x(2)+zm_signal(t)*h/2;
0081       % size of the window
0082       dx(1)=(xx(1)-xi(1))/(w-1);
0083       dx(2)=(xx(2)-xi(2))/(h-1);
0084       
0085       % position of all points in the window
0086       [XI,YI]=meshgrid(xi(1):dx(1):xx(1), xi(2):dx(2):xx(2));
0087       
0088       %%%% rotation
0089       % rotate the window's points
0090       alfa=rt_signal(t);
0091       XI=XI-x(1); YI=YI-x(2);
0092       XR=XI.*cos(alfa)+YI.*sin(alfa);
0093       YR=-XI.*sin(alfa)+YI.*cos(alfa);
0094       XI=XR+x(1); YI=YR+x(2);
0095 
0096       % compute the content of the frame by linear interpolation
0097       % this is a workaround for a bug in Matlab 7.0.0.19901 (R14)
0098       [M,N] = size(im);
0099       PATCH=interp2(1:N,1:M, im, XI, YI, '*linear');
0100       % it is also possible to perform cubic interpolation,
0101       % but it's much slower:
0102       %PATCH=interp2(im, XI, YI, '*cubic');
0103 
0104       % if the frame went out of the image, discard the sequence and
0105       % start from scratch
0106       if max(isnan(PATCH(:))),
0107     repeat=1; break;
0108       end
0109     
0110       % save the current frame
0111       DATA(t,:)=PATCH(:)';
0112     end
0113   end

Generated on Thu 24-Mar-2005 09:54:48 by m2html © 2003