Home > vbmeg > external > bioelectromagnetism > avw_view.m

avw_view

PURPOSE ^

avw_view - create and navigate ortho views of Analyze 7.5 volume

SYNOPSIS ^

function [ varargout ] = avw_view(avw,parent,command),

DESCRIPTION ^

 avw_view - create and navigate ortho views of Analyze 7.5 volume
 
 [ avw ] = avw_view([avw], [parent], [command])
 
 avw - a struct, created by avw_read; if omitted, a gui file locator will
 prompt for a .hdr file.
 
 parent  - an optional handle to the gui that calls this gui, useful for
 updating the UserData field of the parent. The avw structure may be
 returned to the parent, if possible.
 
 command - an optional string, such as 'init' or various callback
 commands, 'init' is the default.
 
 The navigation is by sliders, mouse clicks and arrow keys.  Right mouse
 clicks on any ortho-view will show a command menu, for simple block
 region of interest (ROI) calculations, image zoom, and save image.  The
 ROI calculations are returned into avw.stats.
 
 Fiducial points can be selected, which are returned into 'avw.fiducials'
 in the base workspace. These points are given in several coordinate
 frameworks (voxels, mm, and meters), with values given relative to an
 origin located at the "center" of the MRI volume (see avw_center, which
 returns abs and corner values, abs used here).
 
 The AC location can be selected and the values are returned into 'avw.ac'
 in the base workspace. These points are given in voxels, mm & meters; for
 the latter, the values are given as offsets from the "center" of the MRI
 volume (see avw_center).
 
 +X is left (L), +Y is anterior (A), +Z is superior (S), the default LAS
 orientation of the Analyze 7.5 format.  The coordinate system is left
 handed.  This is the radiological convention, as opposed to the
 neurological convention (RAS).  The latter can be emulated by using the
 'Flip L/R' button.
 
 Example of loading and viewing the SPM T1 template:
 avw = avw_read('T1')
 avw = avw_view(avw);
 
 Similarly, just 'avw_view' can be typed at the command prompt and you can
 use the gui file locator to select any .hdr file.

 See also, avw_read, avw_img_read, avw_hdr_read

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ varargout ] = avw_view(avw,parent,command),
0002 
0003 % avw_view - create and navigate ortho views of Analyze 7.5 volume
0004 %
0005 % [ avw ] = avw_view([avw], [parent], [command])
0006 %
0007 % avw - a struct, created by avw_read; if omitted, a gui file locator will
0008 % prompt for a .hdr file.
0009 %
0010 % parent  - an optional handle to the gui that calls this gui, useful for
0011 % updating the UserData field of the parent. The avw structure may be
0012 % returned to the parent, if possible.
0013 %
0014 % command - an optional string, such as 'init' or various callback
0015 % commands, 'init' is the default.
0016 %
0017 % The navigation is by sliders, mouse clicks and arrow keys.  Right mouse
0018 % clicks on any ortho-view will show a command menu, for simple block
0019 % region of interest (ROI) calculations, image zoom, and save image.  The
0020 % ROI calculations are returned into avw.stats.
0021 %
0022 % Fiducial points can be selected, which are returned into 'avw.fiducials'
0023 % in the base workspace. These points are given in several coordinate
0024 % frameworks (voxels, mm, and meters), with values given relative to an
0025 % origin located at the "center" of the MRI volume (see avw_center, which
0026 % returns abs and corner values, abs used here).
0027 %
0028 % The AC location can be selected and the values are returned into 'avw.ac'
0029 % in the base workspace. These points are given in voxels, mm & meters; for
0030 % the latter, the values are given as offsets from the "center" of the MRI
0031 % volume (see avw_center).
0032 %
0033 % +X is left (L), +Y is anterior (A), +Z is superior (S), the default LAS
0034 % orientation of the Analyze 7.5 format.  The coordinate system is left
0035 % handed.  This is the radiological convention, as opposed to the
0036 % neurological convention (RAS).  The latter can be emulated by using the
0037 % 'Flip L/R' button.
0038 %
0039 % Example of loading and viewing the SPM T1 template:
0040 % avw = avw_read('T1')
0041 % avw = avw_view(avw);
0042 %
0043 % Similarly, just 'avw_view' can be typed at the command prompt and you can
0044 % use the gui file locator to select any .hdr file.
0045 %
0046 % See also, avw_read, avw_img_read, avw_hdr_read
0047 %
0048 
0049 % $Revision: 1332 $ $Date:: 2011-02-24 15:57:20 +0900#$
0050 
0051 % Licence:  GNU GPL, no express or implied warranties
0052 % History:  06/2002, Darren.Weber_at_flinders.edu.au
0053 %           10/2002, Darren.Weber_at_flinders.edu.au
0054 %                    added fiducial point determination
0055 %                    changed plots from surf to imagesc commands
0056 %                    added handling of datatype for avw.img
0057 %                    altered daspect to use avw.hdr.dime.pixdim
0058 %                    altered color scheme
0059 %           01/2003, Darren.Weber_at_flinders.edu.au
0060 %                    added parent GUI handling
0061 %           10/2003, Darren.Weber_at_radiology.ucsf.edu
0062 %                    added right click options, including simple block ROI
0063 %                    functions, zoom and save image
0064 %           11/2003, Darren.Weber_at_radiology.ucsf.edu
0065 %                    added arrow key navigation
0066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0067 
0068 if gcbf,
0069     AVWVIEW = get(gcbf,'Userdata');
0070 end
0071 
0072 if ~exist('command','var'), command = 'init'; end
0073 
0074 command = lower(command);
0075 
0076 % Check for specific keys and assign command
0077 if strcmp(command, 'keypress'),
0078   
0079   cc = get(AVWVIEW.gui,'CurrentCharacter');
0080   cc = double(cc);
0081   if cc,
0082     switch cc,
0083       case 27, command = 'quit';  % ESC
0084       case 28, command = 'left';  % left
0085       case 29, command = 'right'; % right
0086       case 30, command = 'up';    % up
0087       case 31, command = 'down';  % down
0088       otherwise, return;  % all other keys
0089     end
0090   end
0091 end
0092 
0093 switch command,
0094     
0095   case 'init',
0096     
0097     if ~exist('avw','var'),
0098       avw = avw_read;
0099     end
0100     
0101     if nargin == 0,
0102       AVWVIEW = init(avw);
0103     elseif isempty(inputname(1)),
0104       AVWVIEW = init(avw);
0105     else
0106       AVWVIEW = init(avw,inputname(1));
0107     end
0108     
0109     AVWVIEW = set_coordinates(AVWVIEW);
0110     
0111     
0112     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0113     
0114   case 'coordinates',
0115     
0116     AVWVIEW = set_coordinates(AVWVIEW);
0117     
0118     
0119     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0120     
0121   case 'crosshairs',
0122     
0123     AVWVIEW = set_crosshairs(AVWVIEW);
0124     
0125     
0126   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0127   
0128   case {'axial_image','coronal_image','sagittal_image'},
0129     
0130     switch command,
0131       case 'axial_image',    AVWVIEW.view = 'axi'; axi_update = 0; cor_update = 1; sag_update = 1;
0132       case 'coronal_image',  AVWVIEW.view = 'cor'; axi_update = 1; cor_update = 0; sag_update = 1;
0133       case 'sagittal_image', AVWVIEW.view = 'sag'; axi_update = 1; cor_update = 1; sag_update = 0;
0134     end
0135     
0136     AVWVIEW = get_current_position(AVWVIEW);
0137     
0138     if axi_update,
0139         axial_update(AVWVIEW);
0140     end
0141     if cor_update,
0142         coronal_update(AVWVIEW);
0143     end;
0144     if sag_update,
0145         sagittal_update(AVWVIEW);
0146     end;
0147     
0148     set_display_values(AVWVIEW);
0149     
0150     AVWVIEW = set_crosshairs(AVWVIEW);
0151     
0152     
0153     
0154     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0155     
0156   case {'axial_slider','coronal_slider','sagittal_slider'},
0157     
0158     switch command,
0159       
0160       case 'axial_slider',
0161         AVWVIEW.view = 'axi';
0162         AVWVIEW = get_slider_position(AVWVIEW);
0163         axial_update(AVWVIEW);
0164         
0165       case 'coronal_slider',
0166         AVWVIEW.view = 'cor';
0167         AVWVIEW = get_slider_position(AVWVIEW);
0168         coronal_update(AVWVIEW);
0169         
0170       case 'sagittal_slider',
0171         AVWVIEW.view = 'sag';
0172         AVWVIEW = get_slider_position(AVWVIEW);
0173         sagittal_update(AVWVIEW);
0174     end
0175     
0176     set_display_values(AVWVIEW);
0177     
0178     AVWVIEW = set_crosshairs(AVWVIEW);
0179     
0180     
0181     
0182     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0183     
0184   case {'left','right','up','down'},
0185     
0186     AVWVIEW = get_slider_position(AVWVIEW);
0187     
0188     % what axes are we in?
0189     if isequal(gca, AVWVIEW.handles.axial_axes),
0190       switch command,
0191         case 'left',
0192           % decrease sagittal slice
0193           if AVWVIEW.slices.sag > 1,
0194             AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0195           end
0196         case 'right',
0197           % increase sagittal slice
0198           if AVWVIEW.slices.sag < AVWVIEW.xdim,
0199             AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0200           end
0201         case 'up',
0202           % increase coronal slice
0203           if AVWVIEW.slices.cor < AVWVIEW.ydim,
0204             AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0205           end
0206         case 'down',
0207           % decrease coronal slice
0208           if AVWVIEW.slices.cor > 1,
0209             AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0210           end
0211       end
0212       switch command,
0213         case {'left','right'}
0214           set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0215           Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0216           set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0217           set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0218           set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0219         case {'up','down'},
0220           set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0221           Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0222           set(AVWVIEW.handles.coronal_image,'CData',Scor');
0223           set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0224           set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0225       end
0226     end
0227     
0228     if isequal(gca, AVWVIEW.handles.coronal_axes),
0229       switch command,
0230         case 'left',
0231           % decrease sagittal slice
0232           if AVWVIEW.slices.sag > 1,
0233             AVWVIEW.slices.sag = AVWVIEW.slices.sag - 1;
0234           end
0235         case 'right',
0236           % increase sagittal slice
0237           if AVWVIEW.slices.sag < AVWVIEW.xdim,
0238             AVWVIEW.slices.sag = AVWVIEW.slices.sag + 1;
0239           end
0240         case 'up',
0241           % increase axial slice
0242           if AVWVIEW.slices.axi < AVWVIEW.zdim,
0243             AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0244           end
0245         case 'down',
0246           % decrease axial slice
0247           if AVWVIEW.slices.axi > 1,
0248             AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0249           end
0250       end
0251       switch command,
0252         case {'left','right'}
0253           set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0254           Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0255           set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0256           set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0257           set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0258         case {'up','down'},
0259           set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0260           Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0261           set(AVWVIEW.handles.axial_image,'CData',Saxi');
0262           set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0263           set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0264       end
0265     end
0266     
0267     if isequal(gca, AVWVIEW.handles.sagittal_axes),
0268       switch command,
0269         case 'left',
0270           % decrease sagittal slice
0271           if AVWVIEW.slices.cor > 1,
0272             AVWVIEW.slices.cor = AVWVIEW.slices.cor - 1;
0273           end
0274         case 'right',
0275           % increase sagittal slice
0276           if AVWVIEW.slices.cor < AVWVIEW.ydim,
0277             AVWVIEW.slices.cor = AVWVIEW.slices.cor + 1;
0278           end
0279         case 'up',
0280           % increase axial slice
0281           if AVWVIEW.slices.axi < AVWVIEW.zdim,
0282             AVWVIEW.slices.axi = AVWVIEW.slices.axi + 1;
0283           end
0284         case 'down',
0285           % decrease axial slice
0286           if AVWVIEW.slices.axi > 1,
0287             AVWVIEW.slices.axi = AVWVIEW.slices.axi - 1;
0288           end
0289       end
0290       switch command,
0291         case {'left','right'}
0292           set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0293           Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0294           set(AVWVIEW.handles.coronal_image,'CData',Scor');
0295           set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0296           set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0297         case {'up','down'},
0298           set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0299           Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0300           set(AVWVIEW.handles.axial_image,'CData',Saxi');
0301           set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0302           set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0303       end
0304     end
0305     
0306     AVWVIEW = set_crosshairs(AVWVIEW);
0307     
0308     
0309     
0310     
0311     
0312     
0313     
0314     
0315     
0316     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0317     
0318   case {'roi_9','roi_7','roi_5','roi_3'},
0319     
0320     position = [ AVWVIEW.slices.sag, AVWVIEW.slices.cor, AVWVIEW.slices.axi ];
0321     
0322     shape.type = 'block';
0323     if findstr(command,'9'), shape.size = [9,9,9]; end
0324     if findstr(command,'7'), shape.size = [7,7,7]; end
0325     if findstr(command,'5'), shape.size = [5,5,5]; end
0326     if findstr(command,'3'), shape.size = [3,3,3]; end
0327     
0328     stats.roi = avw_roi(AVWVIEW.avw,position,shape);
0329     
0330     AVWVIEW.avw.stats = avw_stats(stats);
0331     
0332     
0333     
0334     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0335     
0336   case {'nasion','rpa','lpa','ac'},
0337     
0338     % return voxel coordinates into AVWVIEW.imgXYZ
0339     AVWVIEW = slices2metric(AVWVIEW);
0340     
0341     if get(AVWVIEW.handles.coord,'value') == 2,
0342       format = '%7.3f %7.3f %7.3f';
0343       imgXYZ = AVWVIEW.imgXYZ.mm;
0344       string = sprintf('%7.3f %7.3f %7.3f',imgXYZ);
0345     elseif get(AVWVIEW.handles.coord,'value') == 3,
0346       format = '%7.3f %7.3f %7.3f';
0347       imgXYZ = AVWVIEW.imgXYZ.meters;
0348       string = sprintf('%7.3f %7.3f %7.3f',imgXYZ);
0349     else
0350       imgXYZ = AVWVIEW.imgXYZ.voxels;
0351       string = sprintf('%7.0f %7.0f %7.0f',imgXYZ);
0352     end;
0353     
0354     switch command,
0355       case 'nasion',
0356         set(AVWVIEW.handles.nasion,'String',string);
0357         AVWVIEW.avw.fiducials.nasion.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0358         AVWVIEW.avw.fiducials.nasion.meters(1,:) = AVWVIEW.imgXYZ.meters;
0359         AVWVIEW.avw.fiducials.nasion.mm(1,:)     = AVWVIEW.imgXYZ.mm;
0360       case 'rpa',
0361         set(AVWVIEW.handles.rpa,'String',string);
0362         AVWVIEW.avw.fiducials.rpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0363         AVWVIEW.avw.fiducials.rpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
0364         AVWVIEW.avw.fiducials.rpa.mm(1,:)     = AVWVIEW.imgXYZ.mm;
0365       case 'lpa',
0366         set(AVWVIEW.handles.lpa,'String',string);
0367         AVWVIEW.avw.fiducials.lpa.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0368         AVWVIEW.avw.fiducials.lpa.meters(1,:) = AVWVIEW.imgXYZ.meters;
0369         AVWVIEW.avw.fiducials.lpa.mm(1,:)     = AVWVIEW.imgXYZ.mm;
0370       case 'ac',
0371         set(AVWVIEW.handles.ac,'String',string);
0372         AVWVIEW.avw.ac.voxels(1,:) = AVWVIEW.imgXYZ.voxels;
0373         AVWVIEW.avw.ac.meters(1,:) = AVWVIEW.imgXYZ.meters;
0374         AVWVIEW.avw.ac.mm(1,:) = AVWVIEW.imgXYZ.mm;
0375     end
0376     
0377     
0378     
0379     
0380     
0381     
0382     
0383     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0384     
0385   case 'flip',
0386     
0387     % flip X dim here...
0388     AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
0389     
0390     if isfield(AVWVIEW.handles,'axial_image'),
0391       Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0392       set(AVWVIEW.handles.axial_image,'CData',Saxi');
0393     end;
0394     if isfield(AVWVIEW.handles,'coronal_image'),
0395       Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0396       set(AVWVIEW.handles.coronal_image,'CData',Scor');
0397     end;
0398     if isfield(AVWVIEW.handles,'sagittal_image'),
0399       Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0400       set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0401     end;
0402     
0403     flipStatus = get(AVWVIEW.handles.flipStatus,'string');
0404     if strmatch(flipStatus,'R>>L (radiological)'),
0405       flipStatus = 'L>>R (neurological)';
0406     else,
0407       flipStatus = 'R>>L (radiological)';
0408     end;
0409     set(AVWVIEW.handles.flipStatus,'string',flipStatus);
0410     
0411     
0412     
0413     
0414     
0415     
0416     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0417     
0418   case {'brighter','dimmer','setclimit'},
0419     
0420     switch command,
0421       case 'brighter',
0422         AVWVIEW.clim = AVWVIEW.clim .* 0.9;
0423       case 'dimmer',
0424         AVWVIEW.clim = AVWVIEW.clim .* 1.1;
0425       case 'setclimit',
0426         clim = get(AVWVIEW.handles.clim,'string');
0427         AVWVIEW.clim(2) = str2num(clim);
0428     end
0429     climString = sprintf('%05.2f',AVWVIEW.clim(2));
0430     set(AVWVIEW.handles.clim,'string',climString);
0431     
0432     if isfield(AVWVIEW.handles,'axial_image'),
0433       set(AVWVIEW.handles.axial_axes,'Clim',AVWVIEW.clim);
0434     end;
0435     if isfield(AVWVIEW.handles,'coronal_image'),
0436       set(AVWVIEW.handles.coronal_axes,'Clim',AVWVIEW.clim);
0437     end;
0438     if isfield(AVWVIEW.handles,'sagittal_image'),
0439       set(AVWVIEW.handles.sagittal_axes,'Clim',AVWVIEW.clim);
0440     end;
0441     
0442     
0443     
0444     
0445     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0446     
0447   case 'contrast'
0448     
0449     if isfield(AVWVIEW.handles,'axial_image'),
0450       X = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0451       AVWVIEW.cmap = contrast(X);
0452       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0453     end;
0454     if isfield(AVWVIEW.handles,'coronal_image'),
0455       X = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0456       AVWVIEW.cmap = contrast(X);
0457       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0458     end;
0459     if isfield(AVWVIEW.handles,'sagittal_image'),
0460       X = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0461       AVWVIEW.cmap = contrast(X);
0462       colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmap);
0463     end;
0464     
0465     
0466     
0467     
0468     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0469     
0470   case 'setcmap'
0471     
0472     cmapIndex = get(AVWVIEW.handles.cmap,'value');
0473     cmapString = get(AVWVIEW.handles.cmap,'string');
0474     
0475     AVWVIEW.cmapString = cmapString{cmapIndex};
0476     
0477     if isfield(AVWVIEW.handles,'axial_image'),
0478       AVWVIEW.cmap = colormap(AVWVIEW.handles.axial_axes,AVWVIEW.cmapString);
0479     end;
0480     if isfield(AVWVIEW.handles,'coronal_image'),
0481       AVWVIEW.cmap = colormap(AVWVIEW.handles.coronal_axes,AVWVIEW.cmapString);
0482     end;
0483     if isfield(AVWVIEW.handles,'sagittal_image'),
0484       AVWVIEW.cmap = colormap(AVWVIEW.handles.sagittal_axes,AVWVIEW.cmapString);
0485     end;
0486     
0487     
0488     
0489     
0490     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0491     
0492   case 'histogram',
0493     
0494     avw = AVWVIEW.avw;
0495     
0496     % would be nice to use bins that reflect
0497     % the bits per pixel, but it seems to take
0498     % forever for a 16 bit image, otherwise
0499     % use this code:
0500     %     %check the bits per pixel of avw
0501     %     bitpix = avw.hdr.dime.bitpix;
0502     %     % set the bins according to the data type
0503     %     if bitpix <= 8, bins = 0:255; end
0504     %     if bitpix > 8,  bins = 0:65535; end
0505     
0506     %bins = linspace(0,intensity_max,255);
0507     
0508     intensity_min = min(min(min(avw.img)));
0509     intensity_max = max(max(max(avw.img)));
0510     
0511     bins = intensity_min:intensity_max;
0512     
0513     fprintf('...calculating histogram for %d bins.\n',length(bins));
0514     
0515     for i=1:size(avw.img,3),
0516       n = hist(avw.img(:,:,i), bins);
0517       if i == 1,
0518         intensity_volume = sum(n,2);
0519       else
0520         intensity_slice = sum(n,2);
0521         intensity_volume = intensity_volume + intensity_slice;
0522       end
0523     end
0524     figure('name','intensity histogram');
0525     bar(bins,intensity_volume);
0526     
0527     
0528     
0529     
0530     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0531     
0532   case 'zoom'
0533     
0534     x = AVWVIEW.slices.sag;
0535     y = AVWVIEW.slices.cor;
0536     z = AVWVIEW.slices.axi;
0537     
0538     switch AVWVIEW.view,
0539       case 'axi',
0540         slice = rot90(AVWVIEW.avw.img(:,:,z));
0541       case 'cor',
0542         slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0543       case 'sag',
0544         slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0545     end
0546     
0547     figure;
0548     imagesc(slice,AVWVIEW.clim); 
0549     colormap(gray); axis off; zoom on;
0550     daspect(AVWVIEW.daspect);
0551     
0552     
0553     
0554     
0555     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0556     
0557   case 'save_image',
0558     
0559     [filename, pathname] = uiputfile(...
0560       { '*.png','PNG Files (*.png)'; ...
0561         '*.jpg','JPG Files (*.jpg)'; ...
0562         '*.ppm;*.pgm;*.pbm','Portable Anymap (*.ppm,*.pgm,*.pbm)'; ...
0563         '*.*',  'All Files (*.*)'}, ...
0564       'IMWrite to file');
0565     
0566     if filename,
0567       
0568       x = AVWVIEW.slices.sag;
0569       y = AVWVIEW.slices.cor;
0570       z = AVWVIEW.slices.axi;
0571       
0572       pixelsPerMM = 1 ./ double(AVWVIEW.avw.hdr.dime.pixdim(2:4));
0573       pixelsPerMeter = pixelsPerMM .* 1000;
0574       
0575       switch AVWVIEW.view,
0576         case 'axi',
0577           slice = rot90(AVWVIEW.avw.img(:,:,z));
0578           xresolution = pixelsPerMeter(1);
0579           yresolution = pixelsPerMeter(2);
0580         case 'cor',
0581           slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0582           xresolution = pixelsPerMeter(1);
0583           yresolution = pixelsPerMeter(3);
0584         case 'sag',
0585           slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0586           xresolution = pixelsPerMeter(2);
0587           yresolution = pixelsPerMeter(3);
0588       end
0589       
0590       % scale the image values to between 0-1 for imwrite
0591       % (initially used max of slice, but actually want to
0592       % use the scaled intensity from the gui).
0593       %maxValue = max(max(slice));
0594       %scaledSlice = slice ./ maxValue;
0595       scaledSlice = slice ./ AVWVIEW.clim(2);
0596       
0597       % RGB = ind2rgb(X,map) converts the matrix X and corresponding
0598       % colormap map to RGB (truecolor)
0599       
0600       file = [pathname,filename];
0601       fprintf('saving to:...%s\n',file);
0602       
0603       %Most of the supported image file formats store uint8 data.
0604       %PNG and TIFF formats additionally support uint16 data. For
0605       %grayscale and RGB images, if the data array is double, the
0606       %assumed dynamic range is [0,1]. The data array is automatically
0607       %scaled by 255 before being written as uint8. If the data array
0608       %is uint8 or uint16, it is written without scaling as uint8 or
0609       %uint16, respectively.
0610       
0611       [pathname,filename,ext] = fileparts([pathname,filename]);
0612       
0613       switch ext,
0614       
0615         case '.png',
0616           %imwrite(uint8(image),colormap,file,format);
0617           %imwrite(slice,colormap(gray),file,format,...
0618           
0619           %     'XResolution'  A scalar indicating the number of
0620           %                    pixels/unit in the horizontal direction
0621           %
0622           %     'YResolution'  A scalar indicating the number of
0623           %                    pixels/unit in the vertical direction
0624           %
0625           %     'ResolutionUnit' Either 'unknown' or 'meter'
0626           format = 'png';
0627           imwrite(scaledSlice,file,format,...
0628             'BitDepth',16,'ResolutionUnit','meter',...
0629             'XResolution',xresolution,...
0630             'YResolution',yresolution);
0631           
0632         case '.jpg',
0633           format = 'jpg';
0634           imwrite(scaledSlice,file,format);
0635         case {'.ppm','.pgm','.pbm'},
0636           format = ext(2:end);
0637           imwrite(scaledSlice,file,format);
0638         otherwise
0639           fprintf('...cannot write %s image files\n',ext);
0640       end
0641     end
0642     
0643     
0644     
0645     
0646     
0647   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0648     
0649   case 'quit',
0650     
0651     flipStatus = get(AVWVIEW.handles.flipStatus,'string');
0652     if strmatch(flipStatus,'L>>R (neurological)'),
0653       fprintf('...returning avw.img to radiological orientation;\n');
0654       fprintf('...use avw_flip to permanently change the orientation.\n');
0655       AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
0656     end;
0657     
0658     % try to assign back into the input struct
0659     if ~isempty(AVWVIEW.invarname),
0660       fprintf('...returning data to base workspace struct ''%s''\n',AVWVIEW.invarname);
0661       assignin('base',AVWVIEW.invarname,AVWVIEW.avw);
0662     elseif evalin('base','exist(''mri'',''var'')'),
0663       fprintf('...returning data to base workspace struct ''mri''\n');
0664       string = ['AVWVIEW = get(', num2str(AVWVIEW.gui),...
0665           ',''Userdata''); mri.data = AVWVIEW.avw; clear AVWVIEW;'];
0666       evalin('base',string);
0667     else
0668       fprintf('...returning data into base workspace struct ''avw''\n');
0669       assignin('base','avw',AVWVIEW.avw);
0670     end
0671     close gcbf;
0672     
0673   otherwise,
0674     
0675 end
0676 
0677 
0678 switch command,
0679   case 'quit',
0680   otherwise,
0681     set(AVWVIEW.gui,'UserData',AVWVIEW);
0682 end
0683 
0684 if nargout > 0,
0685   varargout{1} = AVWVIEW.avw;
0686 end
0687 
0688 
0689 return
0690 
0691 
0692 
0693 
0694 
0695 
0696 
0697 
0698 
0699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0700 % SUBFUNCTIONS
0701 
0702 
0703 
0704 
0705 
0706 
0707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0708 function axial_update(AVWVIEW)
0709 
0710 if isfield(AVWVIEW.handles,'axial_image'),
0711     Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0712     set(AVWVIEW.handles.axial_image,'CData',Saxi');
0713 end
0714 if isfield(AVWVIEW.handles,'axial_sliderN'),
0715     set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0716     set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0717 end
0718 if isfield(AVWVIEW.handles,'axial_slider'),
0719     set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0720 end;
0721 
0722 return
0723 
0724 
0725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0726 function coronal_update(AVWVIEW)
0727 
0728 if isfield(AVWVIEW.handles,'coronal_image'),
0729     Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0730     set(AVWVIEW.handles.coronal_image,'CData',Scor');
0731 end
0732 if isfield(AVWVIEW.handles,'coronal_sliderN'),
0733     set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0734     set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0735 end
0736 if isfield(AVWVIEW.handles,'coronal_slider'),
0737     set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0738 end;
0739 
0740 return
0741 
0742 
0743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0744 function sagittal_update(AVWVIEW)
0745 
0746 if isfield(AVWVIEW.handles,'sagittal_image'),
0747     Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0748     set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0749 end
0750 if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0751     set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0752     set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0753 end
0754 if isfield(AVWVIEW.handles,'sagittal_slider'),
0755     set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0756 end;
0757 
0758 return
0759 
0760 
0761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0762 function AVWVIEW = set_crosshairs(AVWVIEW)
0763 
0764 current_axes = gca;
0765 
0766 if isfield(AVWVIEW.handles,'axial_axes'),
0767   axes(AVWVIEW.handles.axial_axes);
0768   if ishandle(AVWVIEW.handles.axial_xline),
0769     delete(AVWVIEW.handles.axial_xline);
0770   end
0771   if ishandle(AVWVIEW.handles.axial_yline),
0772     delete(AVWVIEW.handles.axial_yline);
0773   end
0774   
0775   AVWVIEW.handles.axial_xlim = get(AVWVIEW.handles.axial_axes,'Xlim');
0776   AVWVIEW.handles.axial_ylim = get(AVWVIEW.handles.axial_axes,'Ylim');
0777   AVWVIEW.handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],...
0778                                      'Ydata',AVWVIEW.handles.axial_ylim,...
0779                                      'ButtonDownFcn','avw_view([],[],''axial_image'');');
0780   AVWVIEW.handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],...
0781                                      'Xdata',AVWVIEW.handles.axial_xlim,...
0782                                      'ButtonDownFcn','avw_view([],[],''axial_image'');');
0783   set(AVWVIEW.handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0784   set(AVWVIEW.handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0785   
0786   if get(AVWVIEW.handles.crosshairs,'value'),
0787     set(AVWVIEW.handles.axial_xline,'visible','on');
0788     set(AVWVIEW.handles.axial_yline,'visible','on');
0789   else
0790     set(AVWVIEW.handles.axial_xline,'visible','off');
0791     set(AVWVIEW.handles.axial_yline,'visible','off');
0792   end
0793   
0794 end
0795 
0796 if isfield(AVWVIEW.handles,'coronal_axes'),
0797   
0798   axes(AVWVIEW.handles.coronal_axes);
0799   if ishandle(AVWVIEW.handles.coronal_xline),
0800     delete(AVWVIEW.handles.coronal_xline);
0801   end
0802   if ishandle(AVWVIEW.handles.coronal_yline),
0803     delete(AVWVIEW.handles.coronal_yline);
0804   end
0805   
0806   AVWVIEW.handles.coronal_xlim = get(AVWVIEW.handles.coronal_axes,'Xlim');
0807   AVWVIEW.handles.coronal_ylim = get(AVWVIEW.handles.coronal_axes,'Ylim');
0808   AVWVIEW.handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],...
0809                                        'Ydata',AVWVIEW.handles.coronal_ylim,...
0810                                        'ButtonDownFcn','avw_view([],[],''coronal_image'');');
0811   AVWVIEW.handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],...
0812                                        'Xdata',AVWVIEW.handles.coronal_xlim,...
0813                                        'ButtonDownFcn','avw_view([],[],''coronal_image'');');
0814   set(AVWVIEW.handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0815   set(AVWVIEW.handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0816   
0817   if get(AVWVIEW.handles.crosshairs,'value'),
0818     set(AVWVIEW.handles.coronal_xline,'visible','on');
0819     set(AVWVIEW.handles.coronal_yline,'visible','on');
0820   else
0821     set(AVWVIEW.handles.coronal_xline,'visible','off');
0822     set(AVWVIEW.handles.coronal_yline,'visible','off');
0823   end
0824   
0825 end
0826 
0827 if isfield(AVWVIEW.handles,'sagittal_axes'),
0828   axes(AVWVIEW.handles.sagittal_axes);
0829   if ishandle(AVWVIEW.handles.sagittal_xline),
0830     delete(AVWVIEW.handles.sagittal_xline);
0831   end
0832   if ishandle(AVWVIEW.handles.sagittal_yline),
0833     delete(AVWVIEW.handles.sagittal_yline);
0834   end
0835   
0836   AVWVIEW.handles.sagittal_xlim = get(AVWVIEW.handles.sagittal_axes,'Xlim');
0837   AVWVIEW.handles.sagittal_ylim = get(AVWVIEW.handles.sagittal_axes,'Ylim');
0838   AVWVIEW.handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],...
0839                                         'Ydata',AVWVIEW.handles.sagittal_ylim,...
0840                                         'ButtonDownFcn','avw_view([],[],''sagittal_image'');');
0841   AVWVIEW.handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],...
0842                                         'Xdata',AVWVIEW.handles.sagittal_xlim,...
0843                                         'ButtonDownFcn','avw_view([],[],''sagittal_image'');');
0844   set(AVWVIEW.handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0845   set(AVWVIEW.handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0846   
0847   if get(AVWVIEW.handles.crosshairs,'value'),
0848     set(AVWVIEW.handles.sagittal_xline,'visible','on');
0849     set(AVWVIEW.handles.sagittal_yline,'visible','on');
0850   else
0851     set(AVWVIEW.handles.sagittal_xline,'visible','off');
0852     set(AVWVIEW.handles.sagittal_yline,'visible','off');
0853   end
0854   
0855 end
0856 
0857 axes(current_axes);
0858 
0859 return
0860 
0861 
0862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0863 function AVWVIEW = set_coordinates(AVWVIEW)
0864 
0865 % set the axis coordinates to voxels, mm or meters
0866 
0867 s = size(AVWVIEW.avw.img);
0868 if length(s) > 0, xdim = s(1); else xdim = 1; end
0869 if length(s) > 1, ydim = s(2); else ydim = 1; end
0870 if length(s) > 2, zdim = s(3); else zdim = 1; end
0871 
0872 % initialise for voxel coordinates
0873 xpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(2));
0874 ypixdim = double(AVWVIEW.avw.hdr.dime.pixdim(3));
0875 zpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(4));
0876 xdata = [0 xdim];
0877 ydata = [0 ydim];
0878 zdata = [0 zdim];
0879 
0880 aspect = 1./AVWVIEW.daspect; %AVWVIEW.avw.hdr.dime.pixdim(2:4);
0881 
0882 
0883 if get(AVWVIEW.handles.coord,'value') == 2,    % mm
0884   xdata = xdata .* xpixdim;
0885   ydata = ydata .* ypixdim;
0886   zdata = zdata .* zpixdim;
0887   aspect = [1 1 1];
0888 end
0889 
0890 if get(AVWVIEW.handles.coord,'value') == 3,    % meters
0891   xpixdim = xpixdim / 1000;
0892   ypixdim = ypixdim / 1000;
0893   zpixdim = zpixdim / 1000;
0894   xdata = xdata .* xpixdim;
0895   ydata = ydata .* ypixdim;
0896   zdata = zdata .* zpixdim;
0897   aspect = [1 1 1];
0898 end
0899 
0900 
0901 if isfield(AVWVIEW.handles,'axial_image'),
0902   set(AVWVIEW.handles.axial_axes,'Xlim',xdata);
0903   set(AVWVIEW.handles.axial_axes,'Ylim',ydata);
0904   set(AVWVIEW.handles.axial_axes,'Zlim',zdata);
0905   set(AVWVIEW.handles.axial_image,'Xdata',xdata);
0906   set(AVWVIEW.handles.axial_image,'Ydata',ydata);
0907   daspect(AVWVIEW.handles.axial_axes,aspect([1 2 3]));
0908 end;
0909 if isfield(AVWVIEW.handles,'coronal_image'),
0910   set(AVWVIEW.handles.coronal_axes,'Xlim',xdata);
0911   set(AVWVIEW.handles.coronal_axes,'Ylim',zdata);
0912   set(AVWVIEW.handles.coronal_axes,'Zlim',ydata);
0913   set(AVWVIEW.handles.coronal_image,'Xdata',xdata);
0914   set(AVWVIEW.handles.coronal_image,'Ydata',zdata);
0915   daspect(AVWVIEW.handles.coronal_axes,aspect([1 3 2]));
0916 end;
0917 if isfield(AVWVIEW.handles,'sagittal_image'),
0918   set(AVWVIEW.handles.sagittal_axes,'Xlim',ydata);
0919   set(AVWVIEW.handles.sagittal_axes,'Ylim',zdata);
0920   set(AVWVIEW.handles.sagittal_axes,'Zlim',xdata);
0921   set(AVWVIEW.handles.sagittal_image,'Xdata',ydata);
0922   set(AVWVIEW.handles.sagittal_image,'Ydata',zdata);
0923   daspect(AVWVIEW.handles.sagittal_axes,aspect([2 3 1]));
0924 end;
0925 
0926 set_display_values(AVWVIEW);
0927 
0928 return
0929 
0930 
0931 
0932 
0933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0934 function AVWVIEW = get_current_position(AVWVIEW),
0935 
0936 %[AVWVIEW, metric] = slices2metric(AVWVIEW);
0937 
0938 switch AVWVIEW.view,
0939   case 'sag',
0940     currentpoint = get(get(AVWVIEW.handles.sagittal_image,'Parent'),'CurrentPoint');
0941     metric.cor = currentpoint(1,1);
0942     metric.axi = currentpoint(1,2);
0943     metric.sag = get(AVWVIEW.handles.sagittal_slider,'Value');
0944   case 'cor',
0945     currentpoint = get(get(AVWVIEW.handles.coronal_image,'Parent'),'CurrentPoint');
0946     metric.sag = currentpoint(2,1);
0947     metric.axi = currentpoint(2,2);
0948     metric.cor = get(AVWVIEW.handles.coronal_slider,'Value');
0949   case 'axi',
0950     currentpoint = get(get(AVWVIEW.handles.axial_image,'Parent'),'CurrentPoint');
0951     metric.sag = currentpoint(2,1);
0952     metric.cor = currentpoint(2,2);
0953     metric.axi = get(AVWVIEW.handles.axial_slider,'Value');
0954 end
0955 
0956 AVWVIEW = metric2slices(AVWVIEW,metric);
0957 AVWVIEW = check_slices(AVWVIEW);
0958 
0959 return
0960 
0961 
0962 
0963 
0964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0965 function AVWVIEW = get_slider_position(AVWVIEW),
0966 
0967 [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi] = deal(0);
0968 
0969 if isfield(AVWVIEW.handles,'sagittal_slider'),
0970   if ishandle(AVWVIEW.handles.sagittal_slider),
0971     AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_slider,'Value'));
0972   end
0973 end
0974 if AVWVIEW.slices.sag == 0,
0975   if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0976     if ishandle(AVWVIEW.handles.sagittal_sliderN),
0977       AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_sliderN,'Value'));
0978     end
0979   end
0980 end
0981 
0982 if isfield(AVWVIEW.handles,'coronal_slider'),
0983   if ishandle(AVWVIEW.handles.coronal_slider),
0984     AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_slider,'Value'));
0985   end
0986 end
0987 if AVWVIEW.slices.cor == 0,
0988   if isfield(AVWVIEW.handles,'coronal_sliderN'),
0989     if ishandle(AVWVIEW.handles.coronal_sliderN),
0990       AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_sliderN,'Value'));
0991     end
0992   end
0993 end
0994 
0995 if isfield(AVWVIEW.handles,'axial_slider'),
0996   if ishandle(AVWVIEW.handles.axial_slider),
0997     AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_slider,'Value'));
0998   end
0999 end
1000 if AVWVIEW.slices.axi == 0,
1001   if isfield(AVWVIEW.handles,'axial_sliderN'),
1002     if ishandle(AVWVIEW.handles.axial_sliderN),
1003       AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_sliderN,'Value'));
1004     end
1005   end
1006 end
1007 
1008 AVWVIEW = check_slices(AVWVIEW);
1009 
1010 return
1011 
1012 
1013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 function AVWVIEW = check_slices(AVWVIEW),
1015 
1016 adjust = 0;
1017 
1018 [ SagSize, CorSize, AxiSize ] = size(AVWVIEW.avw.img);
1019 
1020 if AVWVIEW.slices.sag > SagSize,
1021     AVWVIEW.slices.sag = SagSize;
1022     adjust = 1;
1023 end;
1024 if AVWVIEW.slices.sag < 1,
1025     AVWVIEW.slices.sag = 1;
1026     adjust = 1;
1027 end;
1028 if AVWVIEW.slices.cor > CorSize,
1029     AVWVIEW.slices.cor = CorSize;
1030     adjust = 1;
1031 end;
1032 if AVWVIEW.slices.cor < 1,
1033     AVWVIEW.slices.cor = 1;
1034     adjust = 1;
1035 end;
1036 if AVWVIEW.slices.axi > AxiSize,
1037     AVWVIEW.slices.axi = AxiSize;
1038     adjust = 1;
1039 end;
1040 if AVWVIEW.slices.axi < 1,
1041     AVWVIEW.slices.axi = 1;
1042     adjust = 1;
1043 end;
1044 
1045 if adjust,
1046     AVWVIEW = slices2metric(AVWVIEW);
1047 end
1048 
1049 return
1050 
1051 
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1053 function set_display_values(AVWVIEW),
1054 
1055 % get coordinates of selected voxel and the image intensity there
1056 
1057 sag = AVWVIEW.slices.sag;
1058 cor = AVWVIEW.slices.cor;
1059 axi = AVWVIEW.slices.axi;
1060 
1061 imgvalue = AVWVIEW.avw.img(sag,cor,axi);
1062 
1063 set(AVWVIEW.handles.imval,'String',sprintf('%7.2f',imgvalue));
1064 set(AVWVIEW.handles.imval,'Value',imgvalue);
1065 
1066 % Now update the image position text for the selected voxel
1067 
1068 [AVWVIEW, metric] = slices2metric(AVWVIEW);
1069 sag = metric.sag;
1070 cor = metric.cor;
1071 axi = metric.axi;
1072 
1073 string = sprintf('%7.3f %7.3f %7.3f',sag,cor,axi);
1074 
1075 set(AVWVIEW.handles.impos,'String',string);
1076 set(AVWVIEW.handles.impos,'Value',[sag,cor,axi]);
1077 
1078 return
1079 
1080 
1081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 function [AVWVIEW,metric] = slices2metric(AVWVIEW),
1083 
1084 AVWVIEW.imgXYZ.voxels = [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi];
1085 AVWVIEW.imgXYZ.meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1086 AVWVIEW.imgXYZ.mm     = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1087 
1088 coord_value = get(AVWVIEW.handles.coord,'value');
1089 
1090 if coord_value == 2,
1091   % using mm
1092   img_mm = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1093   metric.axi = img_mm(3);
1094   metric.cor = img_mm(2);
1095   metric.sag = img_mm(1);
1096 elseif coord_value == 3,
1097   % using meters
1098   img_meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1099   metric.axi = img_meters(3);
1100   metric.cor = img_meters(2);
1101   metric.sag = img_meters(1);
1102 else
1103   % voxels
1104   metric.axi = AVWVIEW.slices.axi;
1105   metric.cor = AVWVIEW.slices.cor;
1106   metric.sag = AVWVIEW.slices.sag;
1107 end;
1108 
1109 return
1110 
1111 
1112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1113 function AVWVIEW = metric2slices(AVWVIEW,metric),
1114 
1115 coord_value = get(AVWVIEW.handles.coord,'value');
1116 
1117 if coord_value == 2,
1118   % using mm
1119   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2));
1120   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3));
1121   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4));
1122   AVWVIEW.slices.axi = round(metric.axi / zpix);
1123   AVWVIEW.slices.cor = round(metric.cor / ypix);
1124   AVWVIEW.slices.sag = round(metric.sag / xpix);
1125 elseif coord_value == 3,
1126   % using meters
1127   xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2)) / 1000;
1128   ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3)) / 1000;
1129   zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4)) / 1000;
1130   AVWVIEW.slices.axi = round(metric.axi / zpix);
1131   AVWVIEW.slices.cor = round(metric.cor / ypix);
1132   AVWVIEW.slices.sag = round(metric.sag / xpix);
1133 else
1134   % voxels
1135   AVWVIEW.slices.axi = round(metric.axi);
1136   AVWVIEW.slices.cor = round(metric.cor);
1137   AVWVIEW.slices.sag = round(metric.sag);
1138 end;
1139 
1140 return
1141 
1142 
1143 
1144 
1145 
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 function AVWVIEW = init(avw,invarname),
1148 
1149 % try to keep track of the input struct
1150 if exist('invarname','var'),
1151   if ~isempty(invarname),
1152     AVWVIEW.invarname = invarname;
1153   else
1154     AVWVIEW.invarname = '';
1155   end
1156 else
1157   AVWVIEW.invarname = '';
1158 end
1159 
1160 % GUI General Parameters
1161 GUIwidth  = 150;
1162 GUIheight = 50;
1163 
1164 version = '[$Revision: 1332 $]';
1165 name = sprintf('AVW View [v%s]',version(12:16));
1166 
1167 if isfield(avw,'fileprefix'),
1168   if ~isempty(avw.fileprefix),
1169     format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
1170     name = strcat(name,' - ',sprintf(format,avw.fileprefix));
1171   end
1172 end
1173 
1174 % The Zbuffer provides smooth slice animations (OpenGL is no good)
1175 GUI = figure('Name',name,'Tag','AVWVIEW','units','characters',...
1176   'BackingStore','off',...
1177   'NumberTitle','off','color',[0 0 0],...
1178   'MenuBar','figure','Position',[1 1 GUIwidth GUIheight],...
1179   'Renderer','zbuffer');
1180 
1181 movegui(GUI,'center');
1182 
1183 set(GUI,'KeyPressFcn','avw_view([],[],''keypress'');');
1184 
1185 AVWVIEW.gui = GUI;
1186 
1187 Font.FontName   = 'Helvetica';
1188 Font.FontUnits  = 'Pixels';
1189 Font.FontSize   = 9;
1190 Font.FontWeight = 'normal';
1191 Font.FontAngle  = 'normal';
1192 
1193 
1194 AVWVIEW.shading = 'flat';
1195 shading(AVWVIEW.shading)
1196 
1197 
1198 
1199 %     % determine the datatype of avw.img
1200 %     switch double(avw.hdr.dime.bitpix),
1201 %     case 1,
1202 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1203 %         avw.img = uint8(avw.img);
1204 %     case 8,
1205 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1206 %         avw.img = uint8(avw.img);
1207 %     case 16,
1208 %         fprintf('...converting avw.img to uint16 for viewing only.\n\n');
1209 %         avw.img = uint16(avw.img);
1210 %     case {32,64},
1211 %         % make sure it is double, not single
1212 %         avw.img = double(avw.img);
1213 %     otherwise,
1214 %         % do nothing, leave it as is
1215 %     end
1216 
1217 
1218 % calculate image stats
1219 intensityMean = mean(mean(mean(avw.img)));
1220 intensityMeanRobust = mean(mean(mean(avw.img(find(avw.img)))));
1221 intensityStdev = std(std(std(avw.img)));
1222 
1223 intensityMax = max(max(max(avw.img)));
1224 
1225 % try to adjust for large intensity extremes
1226 if intensityMax > 255,
1227   % got 16 bit data, at least
1228   adjust = 0.5;
1229 else
1230   adjust = 0.9;
1231 end
1232 %AVWVIEW.clim = [0 (intensityMeanRobust + (10 * intensityStdev)) ];
1233 AVWVIEW.clim = [0 (intensityMax * adjust)];
1234 
1235 
1236 
1237 AVWVIEW.xdim = size(avw.img,1);
1238 AVWVIEW.ydim = size(avw.img,2);
1239 AVWVIEW.zdim = size(avw.img,3);
1240 
1241 AVWVIEW.slices.sag = 1;
1242 AVWVIEW.slices.cor = 1;
1243 AVWVIEW.slices.axi = 1;
1244 if AVWVIEW.xdim > 1, AVWVIEW.slices.sag = floor(AVWVIEW.xdim/2); end
1245 if AVWVIEW.ydim > 1, AVWVIEW.slices.cor = floor(AVWVIEW.ydim/2); end
1246 if AVWVIEW.zdim > 1, AVWVIEW.slices.axi = floor(AVWVIEW.zdim/2); end
1247 
1248 % store the volume center for later reference when
1249 % calculating fiducial locations
1250 center = avw_center(avw);
1251 AVWVIEW.center = center.abs.voxels;
1252 
1253 % set the default origin at the center
1254 AVWVIEW.origin  = AVWVIEW.center;
1255 
1256 AVWVIEW.pixdim = double(avw.hdr.dime.pixdim(2:4));
1257 
1258 AVWVIEW.scale2mm     = AVWVIEW.pixdim;          % vol scale in mm
1259 AVWVIEW.scale2meters = AVWVIEW.pixdim ./ 1000;  % vol scale in meters
1260 AVWVIEW.daspect      = AVWVIEW.pixdim ./ min(AVWVIEW.pixdim);
1261 
1262 xPlotSize = 0.38;
1263 yPlotSize = 0.38;
1264 
1265 AVWVIEW.cmapString = 'gray';
1266 
1267 AVWVIEW.cmap = colormap(AVWVIEW.cmapString);
1268 
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1270 
1271 % Axial Slice
1272 if AVWVIEW.xdim > 1 & AVWVIEW.ydim > 1,
1273   
1274   handles.axial_subplot = subplot('position',[0.075 0.075 xPlotSize yPlotSize]);
1275   
1276   Saxial = squeeze(avw.img(:,:,AVWVIEW.slices.axi));
1277   
1278   %handles.axial_image = pcolor(double(Saxial)); colormap(gray); shading interp
1279   %pcolor(Saxial'); colormap(gray); shading flat
1280   
1281   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(flipdim(gray,1)); colorbar
1282   %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(gray)
1283   %image(avw.img(:,:,20)'); axis image; colormap(gray)
1284   %imagesc(avw.img(:,:,20)'); axis image; colormap(gray)
1285   
1286   %handles.axial_image = image('Cdata',Saxial','CDataMapping','scaled',...
1287   %    'XData',[0 xdim],'YData',[0 ydim]);
1288   
1289   handles.axial_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.ydim],Saxial',AVWVIEW.clim);
1290   
1291   handles.axial_axes = gca;
1292   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1293     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1294   
1295   title('Axial','Color',[1 1 1])
1296   ylabel('Y')
1297   xlabel('X')
1298   %xlabel('(Right <<) X (>> Left)'); % default radiological orientation for Analyze
1299   %xlabel('(Left <<) X (>> Right)')
1300   
1301   % This callback navigates with mouse button click
1302   set(handles.axial_image,'ButtonDownFcn','avw_view([],[],''axial_image'');');
1303   
1304   GUIheight = 0.46;
1305   
1306   if AVWVIEW.zdim > 1,
1307     slider_step(1) = 1/(AVWVIEW.zdim);
1308     slider_step(2) = 1/(AVWVIEW.zdim);
1309     handles.axial_slider = uicontrol('Parent',GUI,'Style','slider',...
1310       'Units','Normalized', Font, ...
1311       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1312       'BusyAction','queue',...
1313       'TooltipString','Axial slice navigation',...
1314       'Min',1,'Max',AVWVIEW.zdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.axi,...
1315       'Callback','avw_view([],[],''axial_slider'');');
1316   end
1317   handles.axial_sliderN = uicontrol('Parent',GUI,'Style','text',...
1318     'Units','Normalized', Font, ...
1319     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1320     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1321     'BusyAction','queue',...
1322     'TooltipString','Axial slice number',...
1323     'String',num2str(AVWVIEW.slices.axi),'Value',AVWVIEW.slices.axi);
1324   handles.axial_sliderT = uicontrol('Parent',GUI,'Style','text',...
1325     'Units','Normalized', Font, ...
1326     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1327     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1328     'BusyAction','queue',...
1329     'TooltipString','Axial slice navigation',...
1330     'String','Axial');
1331   
1332   handles.axial_xlim = get(handles.axial_axes,'Xlim');
1333   handles.axial_ylim = get(handles.axial_axes,'Ylim');
1334   handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.axial_ylim);
1335   handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Xdata',handles.axial_xlim);
1336   set(handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1337   set(handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1338   
1339 end
1340 
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 
1343 % Coronal Slice
1344 if AVWVIEW.xdim > 1 & AVWVIEW.zdim > 1,
1345   
1346   handles.coronal_subplot = subplot('position',[0.075 0.575 xPlotSize yPlotSize]);
1347   
1348   Scor = squeeze(avw.img(:,AVWVIEW.slices.cor,:));
1349   handles.coronal_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.zdim],Scor',AVWVIEW.clim);
1350   
1351   handles.coronal_axes = gca;
1352   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1353     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1354   
1355   %xlabel('(Left <<) X (>> Right)')
1356   %xlabel('(Right <<) X (>> Left)')
1357   xlabel('X')
1358   ylabel('Z')
1359   title('Coronal','Color',[1 1 1])
1360   
1361   % This callback navigates with left click
1362   set(handles.coronal_image,'ButtonDownFcn','avw_view([],[],''coronal_image'');');
1363   
1364   GUIheight = GUIheight - 0.04;
1365   
1366   if AVWVIEW.ydim > 1,
1367     slider_step(1) = 1/(AVWVIEW.ydim);
1368     slider_step(2) = 1/(AVWVIEW.ydim);
1369     handles.coronal_slider = uicontrol('Parent',GUI,'Style','slider',...
1370       'Units','Normalized', Font, ...
1371       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1372       'BusyAction','queue',...
1373       'TooltipString','Coronal slice navigation',...
1374       'Min',1,'Max',AVWVIEW.ydim,'SliderStep',slider_step,'Value',AVWVIEW.slices.cor,...
1375       'Callback','avw_view([],[],''coronal_slider'');');
1376   end
1377   handles.coronal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1378     'Units','Normalized', Font, ...
1379     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1380     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1381     'BusyAction','queue',...
1382     'TooltipString','Coronal slice number',...
1383     'String',num2str(AVWVIEW.slices.cor),'Value',AVWVIEW.slices.cor);
1384   handles.coronal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1385     'Units','Normalized', Font, ...
1386     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1387     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1388     'BusyAction','queue',...
1389     'TooltipString','Coronal slice navigation',...
1390     'String','Coronal');
1391   
1392   handles.coronal_xlim = get(handles.coronal_axes,'Xlim');
1393   handles.coronal_ylim = get(handles.coronal_axes,'Ylim');
1394   handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.coronal_ylim);
1395   handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.coronal_xlim);
1396   set(handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1397   set(handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1398   
1399 end
1400 
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1402 
1403 % Sagittal Slice
1404 if AVWVIEW.ydim > 1 & AVWVIEW.zdim > 1,
1405   
1406   handles.sagittal_subplot = subplot('position',[0.575 0.575 xPlotSize yPlotSize]);
1407   
1408   Ssag = squeeze(avw.img(AVWVIEW.slices.sag,:,:));
1409   handles.sagittal_image = imagesc([0,AVWVIEW.ydim],[0,AVWVIEW.zdim],Ssag',AVWVIEW.clim);
1410   
1411   handles.sagittal_axes = gca;
1412   set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1413     'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1414   
1415   xlabel('Y')
1416   ylabel('Z')
1417   title('Sagittal','Color',[1 1 1])
1418   
1419   % This callback navigates with mouse click
1420   set(handles.sagittal_image,'ButtonDownFcn','avw_view([],[],''sagittal_image'');');
1421   
1422   GUIheight = GUIheight - 0.04;
1423   
1424   if AVWVIEW.xdim > 1,
1425     slider_step(1) = 1/(AVWVIEW.xdim);
1426     slider_step(2) = 1/(AVWVIEW.xdim);
1427     handles.sagittal_slider = uicontrol('Parent',GUI,'Style','slider',...
1428       'Units','Normalized', Font, ...
1429       'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1430       'BusyAction','queue',...
1431       'TooltipString','Sagittal slice navigation',...
1432       'Min',1,'Max',AVWVIEW.xdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.sag,...
1433       'Callback','avw_view([],[],''sagittal_slider'');');
1434   end
1435   handles.sagittal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1436     'Units','Normalized', Font, ...
1437     'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1438     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1439     'BusyAction','queue',...
1440     'TooltipString','Sagittal slice number',...
1441     'String',num2str(AVWVIEW.slices.sag),'Value',AVWVIEW.slices.sag);
1442   handles.sagittal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1443     'Units','Normalized', Font, ...
1444     'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1445     'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1446     'BusyAction','queue',...
1447     'TooltipString','Sagittal slice navigation',...
1448     'String','Sagittal');
1449   
1450   handles.sagittal_xlim = get(handles.sagittal_axes,'Xlim');
1451   handles.sagittal_ylim = get(handles.sagittal_axes,'Ylim');
1452   handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Ydata',handles.sagittal_ylim);
1453   handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.sagittal_xlim);
1454   set(handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1455   set(handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1456   
1457 end
1458 
1459 
1460 
1461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463 % Image Contex Menus
1464 
1465 menu=uicontextmenu;
1466 
1467 % enable right click access to ROI tools
1468 roi = uimenu(menu,'Label','ROI');
1469 uimenu(roi,'Label','ROI (9x9x9 block)','Callback','avw_view([],[],''roi_9'');');
1470 uimenu(roi,'Label','ROI (7x7x7 block)','Callback','avw_view([],[],''roi_7'');');
1471 uimenu(roi,'Label','ROI (5x5x5 block)','Callback','avw_view([],[],''roi_5'');');
1472 uimenu(roi,'Label','ROI (3x3x3 block)','Callback','avw_view([],[],''roi_3'');');
1473 
1474 % save image to graphics file
1475 uimenu(menu,'Label','Save Image','Callback','avw_view([],[],''save_image'');');
1476 
1477 % zoom image to new figure
1478 uimenu(menu,'Label','Zoom Image','Callback','avw_view([],[],''zoom'');');
1479 
1480 if isfield(handles,'axial_image'),
1481   if isempty(get(handles.axial_image,'uicontextmenu')),
1482     set(handles.axial_image,'uicontextmenu',menu);
1483   end
1484 end
1485 if isfield(handles,'coronal_image'),
1486   if isempty(get(handles.coronal_image,'uicontextmenu')),
1487     set(handles.coronal_image,'uicontextmenu',menu);
1488   end
1489 end
1490 if isfield(handles,'sagittal_image'),
1491   if isempty(get(handles.sagittal_image,'uicontextmenu')),
1492     set(handles.sagittal_image,'uicontextmenu',menu);
1493   end
1494 end
1495 
1496 
1497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1499 
1500 % Image Intensity at Mouse Click
1501 
1502 GUIheight = GUIheight - 0.04;
1503 
1504 handles.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1505   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1506   'BackgroundColor', [0 0 0],...
1507   'ForegroundColor', [1 1 1],...
1508   'BusyAction','queue',...
1509   'String','Image Intensity');
1510 handles.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1511   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1512   'BackgroundColor', [0 0 0],...
1513   'ForegroundColor', [1 1 1],...
1514   'BusyAction','queue',...
1515   'String','x','Value',0);
1516 
1517 % Image Position at Mouse Click
1518 
1519 GUIheight = GUIheight - 0.04;
1520 
1521 handles.Timpos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1522   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1523   'BackgroundColor', [0 0 0],...
1524   'ForegroundColor', [1 1 1],...
1525   'BusyAction','queue',...
1526   'String','Image Position');
1527 handles.impos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1528   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1529   'BackgroundColor', [0 0 0],...
1530   'ForegroundColor', [1 1 1],...
1531   'BusyAction','queue',...
1532   'String','xyz','Value',[0 0 0]);
1533 
1534 
1535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 
1538 GUIheight = GUIheight - 0.04;
1539 
1540 handles.flip = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1541   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1542   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1543   'BusyAction','queue',...
1544   'TooltipString','Flip Left and Right (viewer only, see also avw_flip).',...
1545   'String','Flip L/R',...
1546   'Callback','avw_view([],[],''flip'');');
1547 handles.flipStatus = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1548   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1549   'BackgroundColor', [0 0 0],...
1550   'ForegroundColor', [1 1 1],...
1551   'BusyAction','queue',...
1552   'TooltipString','Flipped Status',...
1553   'String','R>>L (radiological)');
1554 
1555 
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558 
1559 % AC Location
1560 
1561 GUIheight = GUIheight - 0.04;
1562 
1563 handles.Tac = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1564   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1565   'BackgroundColor', [.3 .3 .3],...
1566   'ForegroundColor', [1 1 1],...
1567   'BusyAction','queue',...
1568   'TooltipString','AC point in (voxels) or (meter offset from center of volume)',...
1569   'String','AC Point',...
1570   'Callback','avw_view([],[],''ac'');');
1571 handles.ac = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1572   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1573   'BackgroundColor', [0 0 0],...
1574   'ForegroundColor', [1 1 1],...
1575   'BusyAction','queue',...
1576   'TooltipString','These values are offset from volume center.',...
1577   'String','x,y,z');
1578 
1579 % Nasion Location
1580 
1581 GUIheight = GUIheight - 0.04;
1582 
1583 handles.Tnasion = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1584   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1585   'BackgroundColor', [.3 .3 .3],...
1586   'ForegroundColor', [1 1 1],...
1587   'BusyAction','queue',...
1588   'TooltipString','Update Nasion - should be toward +Y',...
1589   'String','Fiducial: Nas',...
1590   'Callback','avw_view([],[],''nasion'');');
1591 handles.nasion = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1592   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1593   'BackgroundColor', [0 0 0],...
1594   'ForegroundColor', [1 1 1],...
1595   'BusyAction','queue',...
1596   'TooltipString','These values are offset from volume center, should be toward +Y',...
1597   'String','x,y,z');
1598 
1599 % Right Preauricular Location
1600 
1601 GUIheight = GUIheight - 0.04;
1602 
1603 handles.Trpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1604   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1605   'BackgroundColor', [.3 .3 .3],...
1606   'ForegroundColor', [1 1 1],...
1607   'BusyAction','queue',...
1608   'TooltipString','Update Right Preauricular - should be toward -X',...
1609   'String','Fiducial: RPA',...
1610   'Callback','avw_view([],[],''rpa'');');
1611 handles.rpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1612   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1613   'BackgroundColor', [0 0 0],...
1614   'ForegroundColor', [1 1 1],...
1615   'BusyAction','queue',...
1616   'TooltipString','These values are offset from volume center, should be toward -X',...
1617   'String','x,y,z');
1618 
1619 % Left Preauricular Location
1620 
1621 GUIheight = GUIheight - 0.04;
1622 
1623 handles.Tlpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1624   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1625   'BackgroundColor', [.3 .3 .3],...
1626   'ForegroundColor', [1 1 1],...
1627   'BusyAction','queue',...
1628   'TooltipString','Update Left Preauricular - should be toward +X',...
1629   'String','Fiducial: LPA',...
1630   'Callback','avw_view([],[],''lpa'');');
1631 handles.lpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1632   'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1633   'BackgroundColor', [0 0 0],...
1634   'ForegroundColor', [1 1 1],...
1635   'BusyAction','queue',...
1636   'TooltipString','These values are offset from volume center, should be toward +X',...
1637   'String','x,y,z');
1638 
1639 
1640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 
1643 GUIheight = GUIheight - 0.04;
1644 
1645 handles.contrast = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1646   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1647   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1648   'BusyAction','queue',...
1649   'TooltipString','Auto contrast with gray colormap',...
1650   'String','Auto Contrast',...
1651   'Callback','avw_view([],[],''contrast'');');
1652 
1653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1655 
1656 GUIheight = GUIheight - 0.04;
1657 
1658 handles.dimmer = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1659   'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1660   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1661   'BusyAction','queue',...
1662   'TooltipString','Dim by 1%',...
1663   'String','Dimmer',...
1664   'Callback','avw_view([],[],''dimmer'');');
1665 
1666 handles.brighter = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1667   'Position',[.65 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1668   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1669   'BusyAction','queue',...
1670   'TooltipString','Brighten by 1%',...
1671   'String','Brighter',...
1672   'Callback','avw_view([],[],''brighter'');');
1673 
1674 handles.clim = uicontrol('Parent',GUI,'Style','edit','Units','Normalized', Font, ...
1675   'Position',[.75 GUIheight .06 .03], 'HorizontalAlignment', 'right',...
1676   'BackgroundColor', [0 0 0],...
1677   'ForegroundColor', [1 1 1],...
1678   'BusyAction','queue',...
1679   'TooltipString','Image intensity Climit (inverse brightness)',...
1680   'String',num2str(AVWVIEW.clim(2)),...
1681   'Callback','avw_view([],[],''setClimit'');');
1682 
1683 handles.cmap = uicontrol('Parent',GUI,'Style','popup','Units','Normalized', Font, ...
1684   'Position',[.82 GUIheight .06 .03], 'HorizontalAlignment', 'left',...
1685   'BackgroundColor', [0 0 0],...
1686   'ForegroundColor', [1 1 1],...
1687   'BusyAction','queue',...
1688   'TooltipString','Color Map',...
1689   'String',{'gray','bone','copper','hot','cool','spring','summer','autumn','winter','hsv','jet'},...
1690   'Callback','avw_view([],[],''setCmap'');');
1691 
1692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1694 
1695 GUIheight = 0.46;
1696 
1697 handles.crosshairs = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
1698   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1699   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1700   'BusyAction','queue',...
1701   'TooltipString','Toggle Crosshairs on/off',...
1702   'String','Crosshairs','Value',1,...
1703   'Callback','avw_view([],[],''crosshairs'');');
1704 
1705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 
1708 GUIheight = GUIheight - 0.04;
1709 
1710 handles.histogram = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1711   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1712   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1713   'BusyAction','queue',...
1714   'TooltipString','Histogram of Volume Intensity',...
1715   'String','Histogram',...
1716   'Callback','avw_view([],[],''histogram'');');
1717 
1718 
1719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1721 
1722 GUIheight = GUIheight - 0.04;
1723 
1724 handles.coord = uicontrol('Parent',GUI,'Style','popupmenu','Units','Normalized', Font, ...
1725   'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1726   'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1727   'BusyAction','queue',...
1728   'TooltipString','Voxel or Mensurated Axis Coordinates',...
1729   'String',{'Voxels','mm','meters'},...
1730   'Callback','avw_view([],[],''coordinates'');');
1731 
1732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1734 
1735 Font.FontWeight = 'bold';
1736 
1737 % View avw.hdr
1738 handles.Bhdr = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1739   'Position',[.92 .05 .07 .03],...
1740   'String','HDR','BusyAction','queue',...
1741   'TooltipString','View the .hdr parameters.',...
1742   'BackgroundColor',[0.0 0.0 0.5],...
1743   'ForegroundColor',[1 1 1], 'HorizontalAlignment', 'center',...
1744   'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
1745   'avw_view_hdr(AVWVIEW.avw,AVWVIEW.gui);',...
1746   'clear AVWVIEW;'));
1747 
1748 % OK: Return the avw!
1749 handles.Bquit = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1750   'Position',[.92 .01 .07 .03],...
1751   'String','RETURN','BusyAction','queue',...
1752   'BackgroundColor',[0.0 0.5 0.0],...
1753   'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
1754   'Callback','avw_view([],[],''quit'');');
1755 
1756 % Update the gui_struct handles for this gui
1757 if exist('parent','var'), AVWVIEW.parent.gui = parent; end
1758 AVWVIEW.avw = avw;
1759 AVWVIEW.handles = handles;
1760 set(AVWVIEW.gui,'Userdata',AVWVIEW);
1761 set(AVWVIEW.gui,'HandleVisibility','callback');
1762 
1763 return
1764 
1765 
1766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1767 function slice_img(avw),
1768 
1769 figure
1770 xslice = 128;
1771 slice = squeeze( avw.img(xslice,:,:) );
1772 imagesc(slice); axis image; colormap('gray')
1773 figure
1774 yslice = 128;
1775 slice = squeeze( avw.img(:,yslice,:) );
1776 imagesc(slice); axis image; colormap('gray')
1777 figure
1778 zslice = 128;
1779 slice = squeeze( avw.img(:,:,zslice) );
1780 imagesc(slice); axis image; colormap('gray')
1781 
1782 return

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005