Home > bioelectromagnetism > AnalyzeMovie.m

AnalyzeMovie

PURPOSE ^

AnalyzeMovie - Save analyze images to a kine-loop AVI

SYNOPSIS ^

function AnalyzeMovie

DESCRIPTION ^

 AnalyzeMovie - Save analyze images to a kine-loop AVI
 
 Options are the size of the movie and the views.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function AnalyzeMovie
0002 
0003 % AnalyzeMovie - Save analyze images to a kine-loop AVI
0004 %
0005 % Options are the size of the movie and the views.
0006 %
0007 
0008 
0009 % NOTE ON UNIX THERE IS NO OPTION TO COMPRESS, SO THE
0010 % FILES GET REALLY BIG!!!
0011 %
0012 % I'll work on compression for a windows version - maybe.
0013 %
0014 
0015 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:23 $
0016 
0017 % Licence:  GNU GPL, no express or implied warranties
0018 % 10/2002, Robert C. Welsh <rcwelsh@umich.edu>
0019 %          University of Michigan, Radiology
0020 % 02/2003, Darren.Weber@flinders.edu.au
0021 %          - attempt to adapt for mri_toolbox, rather than
0022 %            depend on spm
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 
0027 SCCSid  = '0.5';
0028 
0029 global BCH; %- used as a flag to know if we are in batch mode or not.
0030 
0031 %-GUI setup
0032 %-----------------------------------------------------------------------
0033 
0034 SPMid = spm('FnBanner',mfilename,SCCSid);
0035 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Analyze Movie Maker',0);
0036 fprintf('AnalyzeMovie Toolbox 0.5\n');
0037 
0038 spm('FigName','Analyze Image Movie Maker',Finter,CmdLine);
0039 % get the name of the rois file.
0040 
0041 movieSize = spm_input_ui('Movie size?','+1','m',...
0042               ['Small (200x200)|', ...
0043                    'Medium (300x300)|', ...
0044                    'Large (400x400)|'],[1 2 3],1);
0045 
0046 imageView = spm_input_ui('Image View?','+1','m',...
0047               ['Axial|', ...
0048                    'Coronal|', ...
0049                    'Sagitall|All'],[1 2 3 4],1);
0050 
0051 pixSize = [200 300 400];
0052 
0053 movieType= ['a' 'c' 's' 'o'];
0054 
0055 % smoothing parameters
0056 nMovies = spm_input('Number of movies','+1','i','1',1,[0,Inf]);
0057 
0058 if nMovies < 1
0059   spm('alert','Exiting as you requested.','AnalyzeMovie',[],0);
0060   return
0061 end
0062 
0063 
0064 % change this...
0065 spmImgFiles = {};
0066 
0067 
0068 for iMovie = 1:nMovies,
0069     
0070     % change this...
0071     spmImgFiles{iMovie}  = spm_get([0,Inf],'*.img',sprintf(['Pick' ...
0072             ' Image files for movie %d'],iMovie),'./',0);
0073     if (length(spmImgFiles{iMovie})< 2)
0074         spm('alert','Exiting as you requested.','AnalyzeMovie',[],0);
0075         return
0076     end
0077     
0078 end
0079 
0080 % Now extract the files.
0081 
0082 
0083 figMovie=figure;
0084 close(figMovie);
0085 figMovie=figure(figMovie);
0086 set(figMovie,'visible','off');
0087 set(figMovie,'DoubleBuffer','on');
0088 set(figMovie,'color',[0 0 0]);
0089 curPos = get(figMovie,'Position');
0090 set(figMovie,'Position',[curPos(1) curPos(2) pixSize(movieSize) pixSize(movieSize)]);
0091 for iMovie = 1:nMovies,
0092     [movieDir movieName] = fileparts(spmImgFiles{iMovie}(1,:));
0093     newMovieName = fullfile(movieDir,['kine-loop-' ...
0094             movieType(imageView:imageView) '.avi']);
0095     theMovie = avifile(newMovieName);
0096     
0097     
0098     % change this...
0099     spm_progress_bar('Init',size(spmImgFiles{iMovie},1),sprintf(['Movie #' ...
0100             ' %d of %d'],iMovie,nMovies),'Extracting data');
0101     
0102     
0103     
0104     % change spmImgFiles...
0105     for iFile = 1:size(spmImgFiles{iMovie},1),
0106         
0107         spm_progress_bar('Set',iFile);
0108         
0109         
0110         % change this...
0111         volHdr = spm_vol(spmImgFiles{iMovie}(iFile,:));
0112         
0113         
0114         slices = movieView(volHdr);
0115         %aVol = spm_read_vols(spm_vol(spmImgFiles{iMovie}(iFile,:)));
0116         %[nX nY nZ] = size(aVol);
0117         %midX = floor(nX/2);
0118         %midY = floor(nY/2);
0119         %midZ = floor(nZ/2);
0120         switch imageView
0121         case 1
0122             aSlice = slices.aS;
0123             %aSlice = squeeze(aVol(:,:,midZ));
0124         case 2
0125             aSlice = rot90(slices.cS,1);
0126             %aSlice = squeeze(aVol(:,midY,:));
0127         case 3
0128             aSlice = rot90(slices.sS,1);
0129             %aSlice = squeeze(aVol(midX,:,:));
0130         case 4 
0131             aSlice = slices.ortho;
0132         end
0133         aSlice = aSlice/max(max(max(aSlice)));
0134         aSlice = aSlice*256;
0135         image(aSlice);
0136         axis image;
0137         colormap(gray(256));
0138         curFrame = getframe(gca);
0139         theMovie = addframe(theMovie,curFrame);
0140     end
0141     theMovie=close(theMovie);
0142 end
0143 
0144 % Change this...
0145 spm_progress_bar('Clear');
0146 spm_clf(Finter);
0147 spm('FigName','Finished',Finter,CmdLine);
0148 spm('Pointer','Arrow');
0149 
0150 
0151 
0152 close(figMovie);
0153 
0154 fprintf('\nFinished  making movie : %s\n',newMovieName);
0155 
0156 return
0157 
0158 
0159 
0160 
0161 
0162 
0163 %-----------------------------------------------------------
0164 
0165 function results = movieView(vHdr)
0166 
0167 % A macro to build the views (based on spm_orthoviews)
0168 %
0169 % Robert C. Welsh <rcwelsh@umich.edu>
0170 % Radiology, University of Michigan
0171 %
0172 % 2002.10.29, Version 0.1
0173 
0174 bb = [-78 -112 -50; 78 76 85];
0175 Dims = diff(bb)'+1;
0176 
0177 TM0 = [ 1 0 0 -bb(1,1)+1;...
0178     0 1 0 -bb(1,2)+1;...
0179     0 0 1 0;...
0180     0 0 0 1];
0181 CM0 = [ 1 0 0 -bb(1,1)+1;...
0182     0 0 1 -bb(1,3)+1;...
0183     0 1 1 0;...
0184     0 0 0 1];
0185 SM0 = [ 0 -1 0 -bb(1,2)+1;...
0186     0 0 1 -bb(1,3)+1;...
0187     1 0 0 0;...
0188     0 0 0 1];
0189 
0190 TD = [Dims(1) Dims(2)];
0191 CD = [Dims(1) Dims(3)];
0192 SD = [Dims(2) Dims(3)];
0193 
0194 notSure = [1 0 0 0; 0 1 0 0 ; 0 0 1 0; 0 0 0 1];
0195 
0196 TM = inv(TM0*(notSure\vHdr.mat));
0197 CM = inv(CM0*(notSure\vHdr.mat));
0198 SM = inv(SM0*(notSure\vHdr.mat));
0199 
0200 
0201 %
0202 % Change this...
0203 axialSlice = spm_slice_vol(vHdr,TM,TD,0);
0204 coronalSlice = spm_slice_vol(vHdr,CM,CD,0);
0205 sagittalSlice = spm_slice_vol(vHdr,SM,SD,0);
0206 
0207 
0208 
0209 results.aS = axialSlice;
0210 results.cS = coronalSlice;
0211 results.sS = sagittalSlice;
0212 
0213 bigPix = zeros(Dims(2)+Dims(3),Dims(1)+Dims(2));
0214 
0215 bigPix(1:Dims(2),1:Dims(1)) = rot90(axialSlice,1);
0216 bigPix(Dims(2)+1:Dims(2)+Dims(3),1:Dims(1)) = rot90(coronalSlice);
0217 bigPix(Dims(2)+1:Dims(2)+Dims(3),Dims(1)+1:Dims(1)+Dims(2)) = ...
0218     rot90(sagittalSlice);
0219 
0220 results.ortho=bigPix;
0221 
0222 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003