Home > functions > plotfunc > vb_make_movie.m

vb_make_movie

PURPOSE ^

Create movie file.

SYNOPSIS ^

function vb_make_movie(movie_parm)

DESCRIPTION ^

 Create movie file. 

 Different types of figures (brain activity, MEG time course, images 
 supported by MATLAB, and so on) can be displayed simultaneously 
 in a movie. 

 [syntax]
 function vb_make_movie(movie_parm)

 [input]
 movie_parm.movie2avi_property
   Cell array of pairs of properties given to 'movie2avi'. You can make
   the movie slower by setting 'FPS' property. See help of movie2avi.m. 
 movie_parm.figure_property
   Cell array of pairs of properties given to 'figure'. You can change
   background color of the movie by setting 'Color' property. 
 movie_parm.[NX/NY]: 
   Number of subfigures (columns and rows)
 movie_parm.movie_file: 
   Output file name (.avi)
 movie_parm.figpos (optional)
   Position of the figure in PC screen
 movie_parm.subplot: 
   Parameters of subplots. Required parameters are dependent on the
   plotting mode. 

 subplot{i}.mode: 
   Plotting mode for the i-th subplot. 
 mode = 1: Cortical activity plot
 Required parameters
 subplot{i}.sub      : Subplot number in MATLAB format.
 subplot{i}.title_var: <optional> <<string>> Title of subfigure.
 subplot{i}.Z        : Z-current.
 subplot{i}.W        : Smoothing filter matrix.
 subplot{i}.ix_act_ex: Indices of the cortical surface model. 
 subplot{i}.Tdisp    : <optional> <<cell>> Cell of strings displayed
                       with the movie. 
 subplot{i}.ix_sample: Indices of 2nd dim. of Z, or Tdisp, at which
                       data is plotted in each frame of the movie. 
 subplot{i}.V        : Vertices of cortical surface model.
 subplot{i}.F        : Faces of cortical surface model.
 subplot{i}.inf_C    : Color of sulcus/gyrus. It should be empty when
                       plotting folded surface model. 
 subplot{i}.light_flag: <<bool>> If true, light object is created. Note:
                        if 'inf_C' is empty, cortical surface model is
                        assumed to be folded model and light object is
                        forced to be created regardless of this
                        parameter. 
 subplot{i}.angle_var: Plot angle. 
 subplot{i}.plot_parm: Parameters for plotting cortical surface
                       model. See help of 'vb_plot_cortex.m'. 
 subplot{i}.Jmin     : Specify the threshold of dipole current by
                       relative value from 0 to 1. 
 subplot{i}.Jmax     : Specify the Maximum of dipole current by
                       relative value from 0 to 1. 
 subplot{i}.cvar_str : Input variable of colorbar. 
 subplot{i}.axes_tight: <optional> <<bool>> If empty or true, 'axis
                        tight' will be invoked internally. 
 subplot{i}.axes_equal: <optional> <<bool>> If empty or true, 'axis
                        equal' will be invoked internally. 
 subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
                           property name and its value. See help of
                           'axes.m'.

 mode = 2: Contour map of MEG sensors
 Required parameters
 subplot{i}.sub  : Subplot number in MATLAB format.
 subplot{i}.title_var: <optional> <<string>> Title of subfigure.
 subplot{i}.bexp : MEG timecourse. 
 subplot{i}.pick : MEG sensor position. 
 subplot{i}.clim : Minimum and maximum values of colormap.
 subplot{i}.cvar_str: Input variable of colorbar. 
 subplot{i}.ix_sample: Indices of 2nd dim. of bexp, or Tdisp, at which
                       data is plotted in each frame of the movie. 
 subplot{i}.Tdisp    : <optional> <<cell>> Cell of strings displayed
                       with the movie. 
 subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
                           property name and its value. See help of
                           'axes.m'.

 mode = 3: MEG timecourse plot
 Required parameters
 subplot{i}.sub      : Subplot number in MATLAB format.
 subplot{i}.title_var: Title of sub-figure. 
 subplot{i}.bexp     : MEG timecourse [T].
 subplot{i}.Tdisp : Vector of time values for vertical axis. 
 subplot{i}.ix_sample : Indices of 2nd dim. of bexp, or Tdisp, at which
                        data will be plotted in each frame of the
                        movie. 
 subplot{i}.xlabel_var: Label of x axis. If it is a cell array, it is
                    interpreted as a set of properties. See help of
                    xlabel.m. 
 subplot{i}.ylabel_var: Label of y axis. If it is a cell array, it is
                    interpreted as a set of properties. See help of
                    ylabel.m. 
 subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
                           property name and its value. See help of
                           'axes.m'.
 subplot{i}.Tline : <optional> <<vector>> Actual time at which lines are
                    drawn on the plot.

 mode = 4:2D image. 
 Required parameters
 subplot{i}.sub  : Subplot number in MATLAB format.
 subplot{i}.fs   : Font size.
 subplot{i}.title: Title of subfigure (empty for no-title)
 subplot{i}.img  : Cell of 2D images. 
 subplot{i}.ix_f : Vector of indicies of subplot{i}.img shown at
                   (ix_f(:))-th frame. 

 2010-10-03 Taku Yoshioka

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vb_make_movie(movie_parm)
0002 % Create movie file.
0003 %
0004 % Different types of figures (brain activity, MEG time course, images
0005 % supported by MATLAB, and so on) can be displayed simultaneously
0006 % in a movie.
0007 %
0008 % [syntax]
0009 % function vb_make_movie(movie_parm)
0010 %
0011 % [input]
0012 % movie_parm.movie2avi_property
0013 %   Cell array of pairs of properties given to 'movie2avi'. You can make
0014 %   the movie slower by setting 'FPS' property. See help of movie2avi.m.
0015 % movie_parm.figure_property
0016 %   Cell array of pairs of properties given to 'figure'. You can change
0017 %   background color of the movie by setting 'Color' property.
0018 % movie_parm.[NX/NY]:
0019 %   Number of subfigures (columns and rows)
0020 % movie_parm.movie_file:
0021 %   Output file name (.avi)
0022 % movie_parm.figpos (optional)
0023 %   Position of the figure in PC screen
0024 % movie_parm.subplot:
0025 %   Parameters of subplots. Required parameters are dependent on the
0026 %   plotting mode.
0027 %
0028 % subplot{i}.mode:
0029 %   Plotting mode for the i-th subplot.
0030 % mode = 1: Cortical activity plot
0031 % Required parameters
0032 % subplot{i}.sub      : Subplot number in MATLAB format.
0033 % subplot{i}.title_var: <optional> <<string>> Title of subfigure.
0034 % subplot{i}.Z        : Z-current.
0035 % subplot{i}.W        : Smoothing filter matrix.
0036 % subplot{i}.ix_act_ex: Indices of the cortical surface model.
0037 % subplot{i}.Tdisp    : <optional> <<cell>> Cell of strings displayed
0038 %                       with the movie.
0039 % subplot{i}.ix_sample: Indices of 2nd dim. of Z, or Tdisp, at which
0040 %                       data is plotted in each frame of the movie.
0041 % subplot{i}.V        : Vertices of cortical surface model.
0042 % subplot{i}.F        : Faces of cortical surface model.
0043 % subplot{i}.inf_C    : Color of sulcus/gyrus. It should be empty when
0044 %                       plotting folded surface model.
0045 % subplot{i}.light_flag: <<bool>> If true, light object is created. Note:
0046 %                        if 'inf_C' is empty, cortical surface model is
0047 %                        assumed to be folded model and light object is
0048 %                        forced to be created regardless of this
0049 %                        parameter.
0050 % subplot{i}.angle_var: Plot angle.
0051 % subplot{i}.plot_parm: Parameters for plotting cortical surface
0052 %                       model. See help of 'vb_plot_cortex.m'.
0053 % subplot{i}.Jmin     : Specify the threshold of dipole current by
0054 %                       relative value from 0 to 1.
0055 % subplot{i}.Jmax     : Specify the Maximum of dipole current by
0056 %                       relative value from 0 to 1.
0057 % subplot{i}.cvar_str : Input variable of colorbar.
0058 % subplot{i}.axes_tight: <optional> <<bool>> If empty or true, 'axis
0059 %                        tight' will be invoked internally.
0060 % subplot{i}.axes_equal: <optional> <<bool>> If empty or true, 'axis
0061 %                        equal' will be invoked internally.
0062 % subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
0063 %                           property name and its value. See help of
0064 %                           'axes.m'.
0065 %
0066 % mode = 2: Contour map of MEG sensors
0067 % Required parameters
0068 % subplot{i}.sub  : Subplot number in MATLAB format.
0069 % subplot{i}.title_var: <optional> <<string>> Title of subfigure.
0070 % subplot{i}.bexp : MEG timecourse.
0071 % subplot{i}.pick : MEG sensor position.
0072 % subplot{i}.clim : Minimum and maximum values of colormap.
0073 % subplot{i}.cvar_str: Input variable of colorbar.
0074 % subplot{i}.ix_sample: Indices of 2nd dim. of bexp, or Tdisp, at which
0075 %                       data is plotted in each frame of the movie.
0076 % subplot{i}.Tdisp    : <optional> <<cell>> Cell of strings displayed
0077 %                       with the movie.
0078 % subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
0079 %                           property name and its value. See help of
0080 %                           'axes.m'.
0081 %
0082 % mode = 3: MEG timecourse plot
0083 % Required parameters
0084 % subplot{i}.sub      : Subplot number in MATLAB format.
0085 % subplot{i}.title_var: Title of sub-figure.
0086 % subplot{i}.bexp     : MEG timecourse [T].
0087 % subplot{i}.Tdisp : Vector of time values for vertical axis.
0088 % subplot{i}.ix_sample : Indices of 2nd dim. of bexp, or Tdisp, at which
0089 %                        data will be plotted in each frame of the
0090 %                        movie.
0091 % subplot{i}.xlabel_var: Label of x axis. If it is a cell array, it is
0092 %                    interpreted as a set of properties. See help of
0093 %                    xlabel.m.
0094 % subplot{i}.ylabel_var: Label of y axis. If it is a cell array, it is
0095 %                    interpreted as a set of properties. See help of
0096 %                    ylabel.m.
0097 % subplot{i}.axes_property: <optional> <<cell>> Cell array of pairs of
0098 %                           property name and its value. See help of
0099 %                           'axes.m'.
0100 % subplot{i}.Tline : <optional> <<vector>> Actual time at which lines are
0101 %                    drawn on the plot.
0102 %
0103 % mode = 4:2D image.
0104 % Required parameters
0105 % subplot{i}.sub  : Subplot number in MATLAB format.
0106 % subplot{i}.fs   : Font size.
0107 % subplot{i}.title: Title of subfigure (empty for no-title)
0108 % subplot{i}.img  : Cell of 2D images.
0109 % subplot{i}.ix_f : Vector of indicies of subplot{i}.img shown at
0110 %                   (ix_f(:))-th frame.
0111 %
0112 % 2010-10-03 Taku Yoshioka
0113 %
0114 % Copyright (C) 2011, ATR All Rights Reserved.
0115 % License : New BSD License(see VBMEG_LICENSE.txt)
0116 
0117 vb_struct2vars(movie_parm,{'NX','NY','movie_file', ...
0118                        'movie2avi_property','figure_property'});
0119 
0120 sp = movie_parm.subplot;
0121 N = length(sp); % Number of subplots
0122 
0123 %
0124 % Maximum movie length
0125 %
0126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0127 Tmax = 0;
0128 for i=1:N
0129   switch sp{i}.mode
0130    case {1,2,3}, 
0131     sp{i}.Tmax = length(sp{i}.ix_sample);
0132    case 4,
0133     sp{i}.Tmax = length(sp{i}.ix_pict);
0134   end
0135   Tmax = max([Tmax sp{i}.Tmax]);
0136 end;
0137 
0138 vb_disp(['Total: ' num2str(Tmax) ' frames']);
0139 
0140 %
0141 % Replace Jmax and Jmin from relative to absolute values
0142 %
0143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0144 for i=1:N
0145   if sp{i}.mode==1, 
0146     J = (sp{i}.W)*(sp{i}.Z);
0147     tmp = max(abs(J(:)));
0148     sp{i}.Jmax = sp{i}.Jmax*tmp;
0149     sp{i}.Jmin = sp{i}.Jmin*tmp;
0150     clear J;
0151   end;
0152 end;
0153 
0154 %
0155 % Create movie
0156 %
0157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0158 for t=1:Tmax
0159   if iscell(figure_property), 
0160     h_fig = figure(figure_property{:});
0161   else
0162     h_fig = figure('Position',[0 100 1024 768]); 
0163   end;
0164 
0165   for i=1:N
0166     subplot(NY,NX,sp{i}.sub);
0167 
0168     % Time step
0169     if t<=sp{i}.Tmax, 
0170       tt = t; 
0171     else 
0172       tt = sp{i}.Tmax; 
0173     end;
0174     
0175     % Plot type
0176     switch sp{i}.mode
0177      case 1, % Cortical activity
0178       vb_struct2vars(sp{i},{'title_var','Z','W','ix_act_ex','Tdisp', ...
0179                             'ix_sample','V','F','inf_C','light_flag', ...
0180                             'angle_var','plot_parm','Jmin','Jmax', ...
0181                             'cbar_var','axes_tight','axes_equal', ...
0182                             'axes_property'});
0183       J = zeros(size(V,1),1);
0184       J(ix_act_ex) = W*Z(:,ix_sample(tt));
0185       h = vb_plot_cortex(plot_parm,V,F,inf_C,J,Jmin,Jmax);
0186       view(angle_var);
0187       
0188       % Axes properties
0189       if ~isempty(axes_tight) & axes_tight==true, 
0190         axis tight;
0191       end;
0192       
0193       if ~isempty(axes_equal) & axes_equal==true, 
0194         axis equal;
0195       end;
0196       
0197       if iscell(axes_property), 
0198         set(gca,axes_property{:});
0199       end;
0200       
0201       % Colorbar
0202       if ~isempty(cbar_var),
0203         colorbar(cbar_var{:});
0204       end;
0205       
0206       % Title
0207       if iscell(title_var), 
0208         title(title_var{:});
0209       elseif ischar(title_var), 
0210         title(title_var);
0211       end;
0212       
0213       % Light
0214       if isempty(inf_C),
0215         camlight(h,'headlight');
0216       elseif light_flag==true,
0217         camlight('headlight');
0218       end;
0219       
0220       % Text
0221       if ~isempty(Tdisp), 
0222         text_var = Tdisp{ix_sample(tt)};
0223         if iscell(text_var), 
0224           text(text_var{:});
0225         else
0226           text(0,0,text_var);
0227         end;
0228       end;
0229 
0230      case 2, % Sensor spatial pattern
0231       vb_struct2vars(sp{i},{'title_var','bexp','pick','clim', ...
0232                           'ix_sample','Tdisp','cbar_var', ...
0233                           'axes_property'});
0234       vb_plot_sensor_2d(pick,bexp(:,ix_sample(tt))',clim);
0235       
0236       % Axes properties
0237       if iscell(axes_property), 
0238         set(gca,axes_property{:});
0239       end;
0240       axis off;
0241       axis equal;
0242       axis tight;
0243       
0244       % Title
0245       if iscell(title_var), 
0246         title(title_var{:});
0247       elseif ischar(title_var), 
0248         title(title_var);
0249       end;
0250       
0251       % Text
0252       if ~isempty(Tdisp), 
0253         text_var = Tdisp{ix_sample(tt)};
0254         if iscell(text_var), 
0255           text(text_var{:});
0256         else
0257           text(0,0,text_var);
0258         end;
0259       end;
0260       
0261       % Colorbar
0262       if ~isempty(cbar_var),
0263         colorbar(cbar_var{:});
0264       end;
0265       
0266      case 3, % MEG timecourse plot
0267       vb_struct2vars(sp{i},{'title_var','bexp','Tdisp','Tline', ...
0268                           'xlabel_var','ylabel_var','ix_sample', ...
0269                           'axes_property'});
0270       
0271       plot(repmat(Tdisp',[1 size(bexp,1)]),bexp');
0272       axis tight;
0273       hold on;
0274       
0275       % Title
0276       if iscell(title_var), 
0277         title(title_var{:});
0278       elseif ischar(title_var), 
0279         title(title_var);
0280       end;
0281       
0282       % Axes property
0283       if iscell(axes_property), 
0284         set(gca,axes_property{:});
0285       end;
0286       
0287       % Xlabel
0288       if iscell(xlabel_var),
0289         xlabel(xlabel_var{:});
0290       elseif ischar(xlabel_var),
0291         xlabel(xlabel_var);
0292       end;
0293 
0294       % Ylabel
0295       if iscell(ylabel_var),
0296         ylabel(ylabel_var{:});
0297       elseif ischar(ylabel_var),
0298         ylabel(ylabel_var);
0299       end;
0300 
0301       % Indicator
0302       yl = ylim;
0303       x = Tdisp(ix_sample(tt));
0304       plot([x x],yl,'EraseMode','xor');
0305 
0306       if ~isempty(Tline),
0307     tmp = reshape(Tline,[1 length(Tline)]);
0308     plot([tmp; tmp],repmat(yl',[1 length(tmp)]),'--');
0309       end;
0310 
0311      case 4, % 2D image
0312       image(sp{i}.img{sp{i}.ix_f(tt)});
0313       axis equal; 
0314       axis tight; 
0315       set(gca,'Visible','off');
0316     end
0317     
0318     if isfield(sp{i},'title'), 
0319       title(sp{i}.title,'FontSize',sp{i}.fs); 
0320     end
0321 
0322     % Axes position
0323     if isfield(sp{i},'axepos'), 
0324       pos = get(gca,'Position'); 
0325       set(gca,'Position',pos+sp{i}.axepos); 
0326     end;
0327   end;
0328 
0329   % Get frame
0330   saved_state = warning('off', 'MATLAB:hg:patch:NotEnoughMemoryForNormals');
0331   drawnow;
0332   frame(t) = getframe(gcf);
0333   warning(saved_state)
0334   close;
0335 end;
0336 
0337 vb_disp('Now creating AVI file ...');
0338 if isempty(movie2avi_property), 
0339   movie2avi(frame,movie_file);
0340 else
0341   movie2avi(frame,movie_file,movie2avi_property{:});
0342 end;
0343 
0344 return;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005