SIMULATION performs a simulation HDL = SIMULATION(INPUT_DIM, IMGS) Perform a simulation. The input dimensionality is reduced to INPUT_DIM dimensions. IMGS is a cell array of filenames of images, from which the image sequences are created. The function returns the handle HDL to the SFA object of the resulting slowly-varying functions. Optional arguments can be specified by appending 'ArgumentName',ArgumentValue pairs to the argument list (e.g. SIMULATION(INPUT_DIM,IMGS,'nsequences',1000,'nframes',50). Possible optional arguments: 'output_dim' (default:200) number of slowly varying functions to compute 'h' (default:16) height of the input patch 'w' (default:16) width of the input patch 'nsequences' (default:2500) total number of sequences to create 'nframes' (default:100) number of frames in each sequence (warning: a change to the number of frames also changes the statistics of the transformations. If you want to compare simulations with different transformation parameters, make sure that nframes stays constant). 'tr_range' (default:75) 'zm_range' (default:[0.3,2]) 'tr','rt','zm' (default:4,8,8) parameters of translation, rotation, and zoom. See IMGSEQUENCE for a description. 'verbose' (default:1) if 1, some text messages are displayed during the simulation and the loaded images are plotted in a window. 'msginterval' (defalut:50), if VERBOSE==1, print a message every MSGINTERVAL sequences See also: IMGSEQUENCE
0001 function hdl = simulation(input_dim, imgs, varargin), 0002 % SIMULATION performs a simulation 0003 % 0004 % HDL = SIMULATION(INPUT_DIM, IMGS) Perform a simulation. The input 0005 % dimensionality is reduced to INPUT_DIM dimensions. IMGS is a cell array 0006 % of filenames of images, from which the image sequences are created. The 0007 % function returns the handle HDL to the SFA object of the resulting 0008 % slowly-varying functions. 0009 % 0010 % Optional arguments can be specified by appending 0011 % 'ArgumentName',ArgumentValue pairs to the argument list 0012 % (e.g. SIMULATION(INPUT_DIM,IMGS,'nsequences',1000,'nframes',50). 0013 % 0014 % Possible optional arguments: 0015 % 'output_dim' (default:200) number of slowly varying functions to 0016 % compute 0017 % 0018 % 'h' (default:16) height of the input patch 0019 % 'w' (default:16) width of the input patch 0020 % 0021 % 'nsequences' (default:2500) total number of sequences to create 0022 % 'nframes' (default:100) number of frames in each sequence (warning: 0023 % a change to the number of frames also changes the statistics of the 0024 % transformations. If you want to compare simulations with different 0025 % transformation parameters, make sure that nframes stays constant). 0026 % 0027 % 'tr_range' (default:75) 0028 % 'zm_range' (default:[0.3,2]) 0029 % 'tr','rt','zm' (default:4,8,8) parameters of translation, rotation, 0030 % and zoom. See IMGSEQUENCE for a description. 0031 % 0032 % 'verbose' (default:1) if 1, some text messages are displayed during 0033 % the simulation and the loaded images are plotted in a window. 0034 % 'msginterval' (defalut:50), if VERBOSE==1, print a message every 0035 % MSGINTERVAL sequences 0036 % 0037 % See also: IMGSEQUENCE 0038 0039 %%%% default values 0040 0041 % number of slowly varying functions to keep 0042 ctxt.output_dim = min(200, xp_dim(input_dim)); 0043 0044 % input patch height and width 0045 ctxt.h = 16; ctxt.w = 16; 0046 % number of sequences, number of frames for each sequence 0047 ctxt.nsequences = 2500; ctxt.nframes=100; 0048 0049 % translation range 0050 ctxt.tr_range = 75; 0051 % zoom range 0052 ctxt.zm_range = [0.3,2]; 0053 % xsequences parameters for translation, rotation and zoom 0054 ctxt.tr = 4; ctxt.rt = 8; ctxt.zm = 8; 0055 0056 % preprocessing method 0057 ctxt.preprocessing = 'PCA'; 0058 0059 % set verbose to zero to disable the messages 0060 ctxt.verbose = 1; 0061 % print a message every msginterval sequences 0062 ctxt.msginterval = 50; 0063 0064 % overwrite with user-defined list of settings 0065 for k = 1:2:length(varargin), 0066 % error check: the optional arguments must be defined as name-value pairs 0067 if ~ischar(varargin{k}), 0068 error 'Setting names must be strings'; 0069 end 0070 % set variable value 0071 ctxt=setfield(ctxt,varargin{k},varargin{k+1}); 0072 end 0073 0074 %%%%%%%%%%%%%%%%%%%%%%%%%%%% 0075 0076 % number of images 0077 nimgs = length(imgs); 0078 % number of sequences per image 0079 nnextimg = fix(ctxt.nsequences/nimgs)+1; 0080 0081 % create an SFA2 object 0082 if ctxt.verbose, fprintf('create a new SFA object\n'); end 0083 hdl = sfa2_create(input_dim, ctxt.output_dim, ctxt.preprocessing); 0084 0085 % loop over the two SFA steps 0086 for step_name = {'preprocessing', 'expansion'}, 0087 % loop over all sequences 0088 for i=1:ctxt.nsequences, 0089 % load a new image every nnextimg sequences 0090 if ~(mod(i,nnextimg)-1), 0091 imgnr = fix(i/nnextimg)+1; 0092 if ctxt.verbose, fprintf('loading image %s\n', imgs{imgnr}); end 0093 img = imread(imgs{imgnr}); 0094 % make sure that the images are made up of double numbers and 0095 % rescale them between 0 and 1 0096 img = double(img)/255.0; 0097 0098 if ctxt.verbose, 0099 clf; imagesc(img); axis off; axis image; colormap(gray); drawnow; 0100 end 0101 end 0102 0103 % print a message every msginterval sequences 0104 if ~mod(i,ctxt.msginterval) & ctxt.verbose, 0105 fprintf('sequence #%d\n',i); 0106 end 0107 0108 % create a new image sequence 0109 DATA = imgsequence(img, ctxt.h, ctxt.w, ctxt.nframes, ctxt.tr_range, ... 0110 ctxt.tr,ctxt.rt, ctxt.zm_range, ctxt.zm); 0111 0112 % update the SFA object 0113 sfa_step(hdl, DATA, step_name{1}); 0114 end 0115 end 0116 0117 % close the SFA algorithm 0118 if ctxt.verbose, fprintf('close the SFA algorithm\n'); end 0119 sfa_step(hdl,[],'sfa');