Home > functions > plotfunc > vb_plot_mri_image.m

vb_plot_mri_image

PURPOSE ^

---

SYNOPSIS ^

function vb_plot_mri_image(plot_parm)

DESCRIPTION ^

 ---
 function vb_plot_mri_image(plot_parm)

 Plot MRI image
 2004-04-16 Taku Yoshioka

 - plot_parm.dir.mri/plot_parm.file.dicom (optional)
 Initial MRI image

 --- Inner functions
 create_frame
 create_axes
 load_mri_image
 update_mri_image

 --- Callback functions
 change_slidebar
 select_mrifile
 select_brainfile
 print_figure
 close_window
 change_plot_parm

 --- Global variables in plot_mri_image_variables
 B (MRI voxel data)
 Vox (BV points)
 Vox2 (Reduced BV points)
 xxP (fMRI/estimated current)
 
 --- GUI handles
 ax1
 ax2
 ax3
 pb1 (Select Brain file)
 pb2 (Print figure)
 pb3 (fMRI)
 sl1 (Slidebar, X axis)
 sl2 (Slidebar, Y axis)
 sl3 (Slidebar, Z axis)
 ---

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_plot_mri_image(plot_parm)
0002 % ---
0003 % function vb_plot_mri_image(plot_parm)
0004 %
0005 % Plot MRI image
0006 % 2004-04-16 Taku Yoshioka
0007 %
0008 % - plot_parm.dir.mri/plot_parm.file.dicom (optional)
0009 % Initial MRI image
0010 %
0011 % --- Inner functions
0012 % create_frame
0013 % create_axes
0014 % load_mri_image
0015 % update_mri_image
0016 %
0017 % --- Callback functions
0018 % change_slidebar
0019 % select_mrifile
0020 % select_brainfile
0021 % print_figure
0022 % close_window
0023 % change_plot_parm
0024 %
0025 % --- Global variables in plot_mri_image_variables
0026 % B (MRI voxel data)
0027 % Vox (BV points)
0028 % Vox2 (Reduced BV points)
0029 % xxP (fMRI/estimated current)
0030 %
0031 % --- GUI handles
0032 % ax1
0033 % ax2
0034 % ax3
0035 % pb1 (Select Brain file)
0036 % pb2 (Print figure)
0037 % pb3 (fMRI)
0038 % sl1 (Slidebar, X axis)
0039 % sl2 (Slidebar, Y axis)
0040 % sl3 (Slidebar, Z axis)
0041 % ---
0042 %
0043 % Copyright (C) 2011, ATR All Rights Reserved.
0044 % License : New BSD License(see VBMEG_LICENSE.txt)
0045 
0046 % plot_parmが構造体でなければ関数名とみなされる
0047 % (コールバック関数を呼び出す)
0048 if ~isstruct(plot_parm)
0049   eval(plot_parm);
0050   return
0051 end
0052 
0053 % Initialize global variables
0054 clear global plot_mri_image_variables
0055 global plot_mri_image_variables;
0056 plot_mri_image_variables.plot_parm = plot_parm;
0057 plot_mri_image_variables.Vox = [];
0058 plot_mri_image_variables.Vox2 = [];
0059 plot_mri_image_variables.xxP = [];
0060 
0061 %
0062 % Create GUI
0063 %
0064 plot_mri_image_variables.ax1 = create_axes([0.1 0.55 0.35 0.35]);
0065 plot_mri_image_variables.ax2 = create_axes([0.55 0.55 0.35 0.35]);
0066 plot_mri_image_variables.ax3 = create_axes([0.1 0.1 0.35 0.35]);
0067 plot_mri_image_variables.sl1 ...
0068     = create_slidebar([0.5 0.46 0.4 0.04],1,256);
0069 plot_mri_image_variables.sl2 ...
0070     = create_slidebar([0.5 0.40 0.4 0.04],2,256);
0071 plot_mri_image_variables.sl3 ...
0072     = create_slidebar([0.5 0.34 0.4 0.04],3,191);
0073 create_button([0.5 0.26 0.12 0.06],'MRI image',...
0074           'vb_plot_mri_image(''select_mrifile'')');
0075 plot_mri_image_variables.pb1 ...
0076     = create_button([0.5 0.18 0.12 0.06],'BV data',...
0077             'vb_plot_mri_image(''select_brainfile'')');
0078 plot_mri_image_variables.pb2 ...
0079     = create_button([0.5 0.1 0.12 0.06],'Print',...
0080             'vb_plot_mri_image(''print_figure'')');
0081 plot_mri_image_variables.pb3 ...
0082     = create_button([0.65 0.26 0.12 0.06],'fMRI',...
0083             'vb_plot_mri_image(''select_fmri'')');
0084 create_button([0.65 0.18 0.12 0.06],'Plot parm.',...
0085           'vb_plot_mri_image(''change_plot_parm'')');
0086 create_button([0.65 0.1 0.12 0.06],'Close',...
0087           'vb_plot_mri_image(''close_window'')');
0088 
0089 set(plot_mri_image_variables.pb1,'Enable','off');
0090 set(plot_mri_image_variables.pb2,'Enable','off');
0091 set(plot_mri_image_variables.pb3,'Enable','off');
0092 
0093 if isfield(plot_parm,'dir')
0094   plot_mri_image_variables.B ...
0095       = readDICOMimages(plot_parm.dir.mri,plot_parm.file.dicom);
0096   update_mri_image;
0097 end
0098 
0099 %
0100 % Create frame
0101 % 2004-03-14 Taku Yoshioka
0102 %
0103 function create_frame(pos)
0104 
0105 uicontrol('Style','frame','Units','normalized',...
0106       'Position',pos);
0107 
0108 %
0109 % Create axes
0110 % 2004-03-12 Taku Yoshioka
0111 %
0112 function h = create_axes(pos,fncstr)
0113 
0114 axes;
0115 set(gca,'Position',pos);
0116 if nargin==2
0117   set(gca,'ButtonDownFcn',fncstr);
0118 end
0119 h = gca;
0120 
0121 %
0122 % Create slidebar
0123 % 2004-04-16 Taku Yoshioka
0124 %
0125 function sl = create_slidebar(pos,i,s_max)
0126 
0127 fncstr = sprintf('vb_plot_mri_image(''change_slidebar(%d)'')',i);
0128 sl = uicontrol('Style','slider','Units','normalized',...
0129            'Position',pos,'Callback',fncstr,...
0130            'Min',1,'Max',s_max,'Value',ceil(s_max/2));
0131 
0132 %
0133 % Select MRI file
0134 % 2004-04-16 Taku Yoshioka
0135 %
0136 function select_mrifile
0137 
0138 global plot_mri_image_variables;
0139 
0140 [pname,fname] = vb_file_select({'.tbl.mat'}); % (.tbl.mat)
0141 
0142 if ~isempty(fname)
0143   fname = fname{1};
0144   plot_mri_image_variables.B = readDICOMimages(pname,fname);
0145   update_mri_image;
0146   set(plot_mri_image_variables.pb1,'Enable','on');
0147   set(plot_mri_image_variables.pb2,'Enable','on');
0148   set(plot_mri_image_variables.pb3,'Enable','on');
0149 end
0150 
0151 %
0152 % Select Brain file
0153 % 2004-04-16 Taku Yoshioka
0154 %
0155 function select_brainfile
0156 
0157 global plot_mri_image_variables;
0158 
0159 [pname,fname] = vb_file_select({'.brain.mat'}); 
0160 
0161 if ~isempty(fname)
0162   fname = fname{1};
0163   if strncmp(fname,'BV-',3)
0164     load([pname fname],'V2R','V2L');
0165     plot_mri_image_variables.Vox = [V2L; V2R];
0166   else
0167     load([pname fname],'Vox');
0168     plot_mri_image_variables.Vox = Vox;
0169   end
0170   update_mri_image;
0171 end
0172 
0173 %
0174 % Create close button
0175 % 2004-03-15 Taku Yoshioka
0176 %
0177 function create_close_button(pos)
0178 
0179 uicontrol('Style','pushbutton','String','Close',...
0180       'Units','normalized','Position',pos,...
0181       'Enable','on','Callback',...
0182       'vb_select_area(''close_window'')');
0183 
0184 %
0185 % Print figure
0186 % 2004-03-16 Taku Yoshioka
0187 %
0188 function print_figure
0189 
0190 global plot_mri_image_variables;
0191 plot_parm = plot_mri_image_variables.plot_parm;
0192 B = plot_mri_image_variables.B;
0193 Vox = plot_mri_image_variables.Vox;
0194 Vox2 = plot_mri_image_variables.Vox2; 
0195 xxP = plot_mri_image_variables.xxP;
0196 sl(1) = ceil(get(plot_mri_image_variables.sl1,'Value'));
0197 sl(2) = ceil(get(plot_mri_image_variables.sl2,'Value'));
0198 sl(3) = ceil(get(plot_mri_image_variables.sl3,'Value'));
0199 x = sl(1);
0200 y = sl(2); 
0201 z = sl(3);
0202 
0203 plot_parm.mtype = 'y.';
0204 plot_parm.msize = plot_parm.ms;
0205 
0206 for i = 1:3
0207   for j = 1:2
0208     h = figure; 
0209     plot_parm.vdim = i;
0210     vb_plot_slice2(B,Vox,Vox2,xxP,sl(i),plot_parm);
0211     hold on;
0212     
0213     switch i
0214      case 1,
0215       plot(xlim,[y y],'w');
0216       plot([z z],ylim,'w');
0217      case 2,
0218       plot(xlim,[x x],'w');
0219       plot([z z],ylim,'w');
0220      case 3,
0221       plot(xlim,[x x],'w');
0222       plot([y y],ylim,'w');
0223     end
0224     
0225     if j==2
0226       switch i
0227        case 1,
0228     xlim([z-30 z+30]);
0229     ylim([y-30 y+30]);
0230        case 2,
0231     xlim([z-30 z+30]);
0232     ylim([x-30 x+30]);
0233        case 3,
0234     xlim([y-30 y+30]);
0235     ylim([x-30 x+30]);
0236       end
0237     end
0238 
0239     vb_epsfig(h,plot_parm.print_ratio,plot_parm.print_size);
0240     figfilename = ['figure' num2str((i-1)*2+j) '.eps'];
0241     print('-depsc2',figfilename);
0242     disp(['Output epsfile as ''' figfilename '''']);
0243     close(h);
0244   end
0245 end
0246 
0247 %
0248 % Change plot parameters
0249 % 2004-03-25 Taku Yoshioka
0250 %
0251 function change_plot_parm
0252 
0253 global plot_mri_image_variables;
0254 
0255 plot_parm = vb_plotparmdlg(plot_mri_image_variables.plot_parm);
0256 plot_mri_image_variables.plot_parm = plot_parm;
0257 update_mri_image;
0258 
0259 %
0260 % Close this window
0261 % 2004-04-02 Taku Yoshioka
0262 %
0263 function close_window
0264 
0265 close;
0266 
0267 %
0268 % Create button
0269 % 2004-04-16 Taku Yoshioka
0270 %
0271 function pb = create_button(pos,str,fncstr)
0272 
0273 pb = uicontrol('Style','pushbutton','String',str,...
0274            'Units','normalized','Position',pos,...
0275            'Callback',fncstr);
0276 
0277 %
0278 % Update MRI image
0279 % 2004-04-16 Taku Yoshioka
0280 %
0281 function update_mri_image(n,erase_line)
0282 
0283 global plot_mri_image_variables;
0284 
0285 plot_parm = plot_mri_image_variables.plot_parm;
0286 ax1 = plot_mri_image_variables.ax1;
0287 ax2 = plot_mri_image_variables.ax2;
0288 ax3 = plot_mri_image_variables.ax3;
0289 sl1 = plot_mri_image_variables.sl1;
0290 sl2 = plot_mri_image_variables.sl2;
0291 sl3 = plot_mri_image_variables.sl3;
0292 Vox = plot_mri_image_variables.Vox;
0293 Vox2 = plot_mri_image_variables.Vox2;
0294 xxP = plot_mri_image_variables.xxP;
0295 
0296 plot_parm.mtype = 'y.';
0297 plot_parm.msize = plot_parm.ms;
0298 x = get(sl1,'Value');
0299 y = get(sl2,'Value');
0300 z = get(sl3,'Value');
0301 
0302 if nargin==0
0303   n = [1 2 3];
0304   erase_line = 0;
0305 elseif nargin==1
0306   erase_line = 0;
0307 end
0308 
0309 if ~isempty(find(n==1))
0310   axes(ax1);
0311   plot_parm.vdim = 1;
0312   [h1,h2,h3] = vb_plot_slice2(plot_mri_image_variables.B,Vox,Vox2,...
0313                xxP,ceil(get(sl1,'Value')),plot_parm);
0314   set(h1,'ButtonDownFcn','vb_plot_mri_image(''change_point(1)'')');
0315   if ~isempty(h2)
0316     set(h2,'ButtonDownFcn','vb_plot_mri_image(''change_point(1)'')');
0317   end
0318   if ~isempty(h3)
0319     set(h3,'ButtonDownFcn','vb_plot_mri_image(''change_point(1)'')');
0320   end
0321   
0322   if ~erase_line
0323     h = plot(xlim,[y y],'w');
0324     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(1)'')');
0325     h = plot([z z],ylim,'w');
0326     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(1)'')');
0327   end
0328 end
0329 
0330 if ~isempty(find(n==2))
0331   axes(ax2);
0332   plot_parm.vdim = 2;
0333   [h1,h2,h3] = vb_plot_slice2(plot_mri_image_variables.B,Vox,Vox2,...
0334               xxP,ceil(get(sl2,'Value')),plot_parm);
0335   set(h1,'ButtonDownFcn','vb_plot_mri_image(''change_point(2)'')');
0336   if ~isempty(h2)
0337     set(h2,'ButtonDownFcn','vb_plot_mri_image(''change_point(2)'')');
0338   end
0339   if ~isempty(h3)
0340     set(h3,'ButtonDownFcn','vb_plot_mri_image(''change_point(2)'')');
0341   end
0342     
0343   if ~erase_line
0344     h = plot(xlim,[x x],'w');
0345     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(2)'')');
0346     h = plot([z z],ylim,'w');
0347     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(2)'')');
0348   end
0349 end
0350 
0351 if ~isempty(find(n==3))
0352   axes(ax3);
0353   plot_parm.vdim = 3;
0354   [h1,h2,h3] = vb_plot_slice2(plot_mri_image_variables.B,Vox,Vox2,...
0355               xxP,ceil(get(sl3,'Value')),plot_parm);
0356   set(h1,'ButtonDownFcn','vb_plot_mri_image(''change_point(3)'')');
0357   if ~isempty(h2)
0358     set(h2,'ButtonDownFcn','vb_plot_mri_image(''change_point(3)'')');
0359   end
0360   if ~isempty(h3)
0361     set(h2,'ButtonDownFcn','vb_plot_mri_image(''change_point(3)'')');
0362   end
0363     
0364   if ~erase_line
0365     h = plot(xlim,[x x],'w');
0366     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(3)'')');
0367     h = plot([y y],ylim,'w');
0368     set(h,'ButtonDownFcn','vb_plot_mri_image(''change_point(3)'')');
0369   end
0370 end
0371 
0372 %
0373 % Change slidebar
0374 % 2004-04-16 Taku Yoshioka
0375 %
0376 function change_slidebar(n)
0377 
0378 update_mri_image;
0379 
0380 %
0381 % Change point
0382 % 2004-04-16 Taku Yoshioka
0383 %
0384 function change_point(n)
0385 
0386 global plot_mri_image_variables;
0387 
0388 ax1 = plot_mri_image_variables.ax1;
0389 ax2 = plot_mri_image_variables.ax2;
0390 ax3 = plot_mri_image_variables.ax3;
0391 sl1 = plot_mri_image_variables.sl1;
0392 sl2 = plot_mri_image_variables.sl2;
0393 sl3 = plot_mri_image_variables.sl3;
0394 
0395 switch n
0396  case 1,
0397   pos = get(ax1,'CurrentPoint');
0398   set(sl3,'Value',ceil(pos(1,1)));
0399   set(sl2,'Value',ceil(pos(1,2)));
0400   
0401  case 2,
0402   pos = get(ax2,'CurrentPoint');
0403   set(sl3,'Value',ceil(pos(1,1)));
0404   set(sl1,'Value',ceil(pos(1,2)));
0405   
0406  case 3,
0407   pos = get(ax3,'CurrentPoint');
0408   set(sl2,'Value',ceil(pos(1,1)));
0409   set(sl1,'Value',ceil(pos(1,2)));
0410 end
0411 
0412 update_mri_image;
0413 
0414 %
0415 % Select fMRI file
0416 % 2004-04-23 Taku Yoshioka
0417 %
0418 function select_fmri
0419 
0420 global plot_mri_image_variables;
0421 
0422 [pname,fname] = vb_file_select({'.fmri.mat'}); 
0423 
0424 if ~isempty(fname)
0425   fname = fname{1};
0426   if ~exist([pname fname])
0427     warndlg('There is no fMRI file.');
0428     return;
0429   end
0430     
0431   % brain file
0432   brainfile = strrep(fname,'.fmri.mat','.brain.mat');
0433   if ~exist([pname fname])
0434     warndlg('There is no brain file.');
0435     return;
0436   else
0437     load([pname brainfile],'Vox');
0438     plot_mri_image_variables.Vox2 = Vox;
0439     msgbox(['Brain file ''' brainfile ''' is loaded.']);
0440     uiwait;
0441   end
0442   
0443   % fMRI key
0444   keyset = get_keyset_fmri([pname fname]);
0445   if isempty(keyset)
0446     warndlg('No fMRI data is registered.');
0447     return;
0448   else
0449     str = [];
0450     for i = 1:length(keyset)-1
0451       str = [str keyset{i} '|'];
0452     end
0453     str = [str keyset{length(keyset)}];
0454   end
0455   
0456   % Create new figure for listing fMRI data
0457   h = figure('MenuBar','none','Name','Select fMRI ID');
0458   plot_mri_image_variables.dlg_handle = h;
0459   pos = [0.1 0.3 0.8 0.6];
0460   h = uicontrol('Style','listbox','Units','normalized',...
0461         'Position',pos,'String',str,...
0462         'Min',1,'Max',1);
0463   pos = [0.1 0.1 0.8 0.1];
0464   uicontrol('Style','pushbutton','Units','normalized',...
0465         'String','OK','Position',pos,...
0466         'Callback','vb_plot_mri_image(''resume'')');
0467   uiwait;
0468   
0469   fmri_key = keyset{get(h,'Value')};
0470   fmri = get_fmri([pname fname],fmri_key);
0471   plot_mri_image_variables.xxP = fmri.xxP;
0472   close(plot_mri_image_variables.dlg_handle);
0473   update_mri_image;
0474 end
0475 
0476 %
0477 % Resume
0478 % 2004-04-23 Taku Yoshioka
0479 %
0480 function resume
0481 
0482 global plot_mri_image_variables;
0483 
0484 uiresume(plot_mri_image_variables.dlg_handle);
0485

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