0001 function AnalyzeMovie
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 SCCSid = '0.5';
0028
0029 global BCH;
0030
0031
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
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
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
0065 spmImgFiles = {};
0066
0067
0068 for iMovie = 1:nMovies,
0069
0070
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
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
0099 spm_progress_bar('Init',size(spmImgFiles{iMovie},1),sprintf(['Movie #' ...
0100 ' %d of %d'],iMovie,nMovies),'Extracting data');
0101
0102
0103
0104
0105 for iFile = 1:size(spmImgFiles{iMovie},1),
0106
0107 spm_progress_bar('Set',iFile);
0108
0109
0110
0111 volHdr = spm_vol(spmImgFiles{iMovie}(iFile,:));
0112
0113
0114 slices = movieView(volHdr);
0115
0116
0117
0118
0119
0120 switch imageView
0121 case 1
0122 aSlice = slices.aS;
0123
0124 case 2
0125 aSlice = rot90(slices.cS,1);
0126
0127 case 3
0128 aSlice = rot90(slices.sS,1);
0129
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
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
0168
0169
0170
0171
0172
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
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