Home > 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: 1.2 $ $Date: 2005/06/27 01:59:59 $
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         [bins,intensity_volume] = avw_histogram(avw);
0509 
0510         figure('name','intensity histogram');
0511         bar(bins,intensity_volume);
0512 
0513 
0514 
0515 
0516         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0517 
0518     case 'zoom'
0519 
0520         x = AVWVIEW.slices.sag;
0521         y = AVWVIEW.slices.cor;
0522         z = AVWVIEW.slices.axi;
0523 
0524         switch AVWVIEW.view,
0525             case 'axi',
0526                 slice = rot90(AVWVIEW.avw.img(:,:,z));
0527             case 'cor',
0528                 slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0529             case 'sag',
0530                 slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0531         end
0532 
0533         figure;
0534         imagesc(slice,AVWVIEW.clim);
0535         colormap(gray); axis off; zoom on;
0536         daspect(AVWVIEW.daspect);
0537 
0538 
0539 
0540 
0541         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0542 
0543     case 'save_image',
0544 
0545         [filename, pathname] = uiputfile(...
0546             { '*.png','PNG Files (*.png)'; ...
0547             '*.jpg','JPG Files (*.jpg)'; ...
0548             '*.ppm;*.pgm;*.pbm','Portable Anymap (*.ppm,*.pgm,*.pbm)'; ...
0549             '*.*',  'All Files (*.*)'}, ...
0550             'IMWrite to file');
0551 
0552         if filename,
0553 
0554             x = AVWVIEW.slices.sag;
0555             y = AVWVIEW.slices.cor;
0556             z = AVWVIEW.slices.axi;
0557 
0558             pixelsPerMM = 1 ./ double(AVWVIEW.avw.hdr.dime.pixdim(2:4));
0559             pixelsPerMeter = pixelsPerMM .* 1000;
0560 
0561             switch AVWVIEW.view,
0562                 case 'axi',
0563                     slice = rot90(AVWVIEW.avw.img(:,:,z));
0564                     xresolution = pixelsPerMeter(1);
0565                     yresolution = pixelsPerMeter(2);
0566                 case 'cor',
0567                     slice = rot90(squeeze(AVWVIEW.avw.img(:,y,:)));
0568                     xresolution = pixelsPerMeter(1);
0569                     yresolution = pixelsPerMeter(3);
0570                 case 'sag',
0571                     slice = rot90(squeeze(AVWVIEW.avw.img(x,:,:)));
0572                     xresolution = pixelsPerMeter(2);
0573                     yresolution = pixelsPerMeter(3);
0574             end
0575 
0576             % scale the image values to between 0-1 for imwrite
0577             % (initially used max of slice, but actually want to
0578             % use the scaled intensity from the gui).
0579             %maxValue = max(max(slice));
0580             %scaledSlice = slice ./ maxValue;
0581             scaledSlice = slice ./ AVWVIEW.clim(2);
0582 
0583             % RGB = ind2rgb(X,map) converts the matrix X and corresponding
0584             % colormap map to RGB (truecolor)
0585 
0586             file = [pathname,filename];
0587             fprintf('saving to:...%s\n',file);
0588 
0589             %Most of the supported image file formats store uint8 data.
0590             %PNG and TIFF formats additionally support uint16 data. For
0591             %grayscale and RGB images, if the data array is double, the
0592             %assumed dynamic range is [0,1]. The data array is automatically
0593             %scaled by 255 before being written as uint8. If the data array
0594             %is uint8 or uint16, it is written without scaling as uint8 or
0595             %uint16, respectively.
0596 
0597             [pathname,filename,ext] = fileparts([pathname,filename]);
0598 
0599             switch ext,
0600 
0601                 case '.png',
0602                     %imwrite(uint8(image),colormap,file,format);
0603                     %imwrite(slice,colormap(gray),file,format,...
0604 
0605                     %     'XResolution'  A scalar indicating the number of
0606                     %                    pixels/unit in the horizontal direction
0607                     %
0608                     %     'YResolution'  A scalar indicating the number of
0609                     %                    pixels/unit in the vertical direction
0610                     %
0611                     %     'ResolutionUnit' Either 'unknown' or 'meter'
0612                     format = 'png';
0613                     imwrite(scaledSlice,file,format,...
0614                         'BitDepth',16,'ResolutionUnit','meter',...
0615                         'XResolution',xresolution,...
0616                         'YResolution',yresolution);
0617 
0618                 case '.jpg',
0619                     format = 'jpg';
0620                     imwrite(scaledSlice,file,format);
0621                 case {'.ppm','.pgm','.pbm'},
0622                     format = ext(2:end);
0623                     imwrite(scaledSlice,file,format);
0624                 otherwise
0625                     fprintf('...cannot write %s image files\n',ext);
0626             end
0627         end
0628 
0629 
0630 
0631 
0632 
0633         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0634 
0635     case 'quit',
0636 
0637         flipStatus = get(AVWVIEW.handles.flipStatus,'string');
0638         if strmatch(flipStatus,'L>>R (neurological)'),
0639             fprintf('...returning avw.img to radiological orientation;\n');
0640             fprintf('...use avw_flip to permanently change the orientation.\n');
0641             AVWVIEW.avw.img = flipdim(AVWVIEW.avw.img,1);
0642         end;
0643 
0644         % try to assign back into the input struct
0645         if ~isempty(AVWVIEW.invarname),
0646             fprintf('...returning data to base workspace struct ''%s''\n',AVWVIEW.invarname);
0647             assignin('base',AVWVIEW.invarname,AVWVIEW.avw);
0648         elseif evalin('base','exist(''mri'',''var'')'),
0649             fprintf('...returning data to base workspace struct ''mri''\n');
0650             string = ['AVWVIEW = get(', num2str(AVWVIEW.gui),...
0651                 ',''Userdata''); mri.data = AVWVIEW.avw; clear AVWVIEW;'];
0652             evalin('base',string);
0653         else
0654             fprintf('...returning data into base workspace struct ''avw''\n');
0655             assignin('base','avw',AVWVIEW.avw);
0656         end
0657         close gcbf;
0658 
0659     otherwise,
0660 
0661 end
0662 
0663 
0664 switch command,
0665     case 'quit',
0666     otherwise,
0667         set(AVWVIEW.gui,'UserData',AVWVIEW);
0668 end
0669 
0670 if nargout > 0,
0671     varargout{1} = AVWVIEW.avw;
0672 end
0673 
0674 
0675 return
0676 
0677 
0678 
0679 
0680 
0681 
0682 
0683 
0684 
0685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0686 % SUBFUNCTIONS
0687 
0688 
0689 
0690 
0691 
0692 
0693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0694 function axial_update(AVWVIEW)
0695 
0696 if isfield(AVWVIEW.handles,'axial_image'),
0697     Saxi = squeeze(AVWVIEW.avw.img(:,:,AVWVIEW.slices.axi));
0698     set(AVWVIEW.handles.axial_image,'CData',Saxi');
0699 end
0700 if isfield(AVWVIEW.handles,'axial_sliderN'),
0701     set(AVWVIEW.handles.axial_sliderN,'String',num2str(AVWVIEW.slices.axi));
0702     set(AVWVIEW.handles.axial_sliderN,'Value',AVWVIEW.slices.axi);
0703 end
0704 if isfield(AVWVIEW.handles,'axial_slider'),
0705     set(AVWVIEW.handles.axial_slider,'Value',AVWVIEW.slices.axi);
0706 end;
0707 
0708 return
0709 
0710 
0711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0712 function coronal_update(AVWVIEW)
0713 
0714 if isfield(AVWVIEW.handles,'coronal_image'),
0715     Scor = squeeze(AVWVIEW.avw.img(:,AVWVIEW.slices.cor,:));
0716     set(AVWVIEW.handles.coronal_image,'CData',Scor');
0717 end
0718 if isfield(AVWVIEW.handles,'coronal_sliderN'),
0719     set(AVWVIEW.handles.coronal_sliderN,'String',num2str(AVWVIEW.slices.cor));
0720     set(AVWVIEW.handles.coronal_sliderN,'Value',AVWVIEW.slices.cor);
0721 end
0722 if isfield(AVWVIEW.handles,'coronal_slider'),
0723     set(AVWVIEW.handles.coronal_slider,'Value',AVWVIEW.slices.cor);
0724 end;
0725 
0726 return
0727 
0728 
0729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0730 function sagittal_update(AVWVIEW)
0731 
0732 if isfield(AVWVIEW.handles,'sagittal_image'),
0733     Ssag = squeeze(AVWVIEW.avw.img(AVWVIEW.slices.sag,:,:));
0734     set(AVWVIEW.handles.sagittal_image,'CData',Ssag');
0735 end
0736 if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0737     set(AVWVIEW.handles.sagittal_sliderN,'String',num2str(AVWVIEW.slices.sag));
0738     set(AVWVIEW.handles.sagittal_sliderN,'Value',AVWVIEW.slices.sag);
0739 end
0740 if isfield(AVWVIEW.handles,'sagittal_slider'),
0741     set(AVWVIEW.handles.sagittal_slider,'Value',AVWVIEW.slices.sag);
0742 end;
0743 
0744 return
0745 
0746 
0747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0748 function AVWVIEW = set_crosshairs(AVWVIEW)
0749 
0750 current_axes = gca;
0751 
0752 [AVWVIEW, metric] = slices2metric(AVWVIEW);
0753 
0754 if isfield(AVWVIEW.handles,'axial_axes'),
0755 
0756     axes(AVWVIEW.handles.axial_axes);
0757     if ishandle(AVWVIEW.handles.axial_xline),
0758         delete(AVWVIEW.handles.axial_xline);
0759     end
0760     if ishandle(AVWVIEW.handles.axial_yline),
0761         delete(AVWVIEW.handles.axial_yline);
0762     end
0763     
0764     AVWVIEW.handles.axial_xlim = get(AVWVIEW.handles.axial_axes,'Xlim');
0765     AVWVIEW.handles.axial_ylim = get(AVWVIEW.handles.axial_axes,'Ylim');
0766     AVWVIEW.handles.axial_xline = line('Xdata',[metric.sag metric.sag],'Ydata',AVWVIEW.handles.axial_ylim);
0767     AVWVIEW.handles.axial_yline = line('Ydata',[metric.cor metric.cor],'Xdata',AVWVIEW.handles.axial_xlim);
0768     set(AVWVIEW.handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0769     set(AVWVIEW.handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0770 
0771     if get(AVWVIEW.handles.crosshairs,'value'),
0772         set(AVWVIEW.handles.axial_xline,'visible','on');
0773         set(AVWVIEW.handles.axial_yline,'visible','on');
0774     else
0775         set(AVWVIEW.handles.axial_xline,'visible','off');
0776         set(AVWVIEW.handles.axial_yline,'visible','off');
0777     end
0778 
0779 end
0780 
0781 if isfield(AVWVIEW.handles,'coronal_axes'),
0782 
0783     axes(AVWVIEW.handles.coronal_axes);
0784     if ishandle(AVWVIEW.handles.coronal_xline),
0785         delete(AVWVIEW.handles.coronal_xline);
0786     end
0787     if ishandle(AVWVIEW.handles.coronal_yline),
0788         delete(AVWVIEW.handles.coronal_yline);
0789     end
0790 
0791     AVWVIEW.handles.coronal_xlim = get(AVWVIEW.handles.coronal_axes,'Xlim');
0792     AVWVIEW.handles.coronal_ylim = get(AVWVIEW.handles.coronal_axes,'Ylim');
0793     AVWVIEW.handles.coronal_xline = line('Xdata',[metric.sag metric.sag],'Ydata',AVWVIEW.handles.coronal_ylim);
0794     AVWVIEW.handles.coronal_yline = line('Ydata',[metric.axi metric.axi],'Xdata',AVWVIEW.handles.coronal_xlim);
0795     set(AVWVIEW.handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0796     set(AVWVIEW.handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0797 
0798     if get(AVWVIEW.handles.crosshairs,'value'),
0799         set(AVWVIEW.handles.coronal_xline,'visible','on');
0800         set(AVWVIEW.handles.coronal_yline,'visible','on');
0801     else
0802         set(AVWVIEW.handles.coronal_xline,'visible','off');
0803         set(AVWVIEW.handles.coronal_yline,'visible','off');
0804     end
0805 
0806 end
0807 
0808 if isfield(AVWVIEW.handles,'sagittal_axes'),
0809     axes(AVWVIEW.handles.sagittal_axes);
0810     if ishandle(AVWVIEW.handles.sagittal_xline),
0811         delete(AVWVIEW.handles.sagittal_xline);
0812     end
0813     if ishandle(AVWVIEW.handles.sagittal_yline),
0814         delete(AVWVIEW.handles.sagittal_yline);
0815     end
0816 
0817     AVWVIEW.handles.sagittal_xlim = get(AVWVIEW.handles.sagittal_axes,'Xlim');
0818     AVWVIEW.handles.sagittal_ylim = get(AVWVIEW.handles.sagittal_axes,'Ylim');
0819     AVWVIEW.handles.sagittal_xline = line('Xdata',[metric.cor metric.cor],'Ydata',AVWVIEW.handles.sagittal_ylim);
0820     AVWVIEW.handles.sagittal_yline = line('Ydata',[metric.axi metric.axi],'Xdata',AVWVIEW.handles.sagittal_xlim);
0821     set(AVWVIEW.handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
0822     set(AVWVIEW.handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
0823 
0824     if get(AVWVIEW.handles.crosshairs,'value'),
0825         set(AVWVIEW.handles.sagittal_xline,'visible','on');
0826         set(AVWVIEW.handles.sagittal_yline,'visible','on');
0827     else
0828         set(AVWVIEW.handles.sagittal_xline,'visible','off');
0829         set(AVWVIEW.handles.sagittal_yline,'visible','off');
0830     end
0831 
0832 end
0833 
0834 axes(current_axes);
0835 
0836 return
0837 
0838 
0839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0840 function AVWVIEW = set_coordinates(AVWVIEW)
0841 
0842 % set the axis coordinates to voxels, mm or meters
0843 
0844 s = size(AVWVIEW.avw.img);
0845 if length(s) > 0, xdim = s(1); else xdim = 1; end
0846 if length(s) > 1, ydim = s(2); else ydim = 1; end
0847 if length(s) > 2, zdim = s(3); else zdim = 1; end
0848 
0849 % initialise for voxel coordinates
0850 xpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(2));
0851 ypixdim = double(AVWVIEW.avw.hdr.dime.pixdim(3));
0852 zpixdim = double(AVWVIEW.avw.hdr.dime.pixdim(4));
0853 xdata = [0 xdim];
0854 ydata = [0 ydim];
0855 zdata = [0 zdim];
0856 
0857 aspect = 1./AVWVIEW.daspect; %AVWVIEW.avw.hdr.dime.pixdim(2:4);
0858 
0859 
0860 if get(AVWVIEW.handles.coord,'value') == 2,    % mm
0861     xdata = xdata .* xpixdim;
0862     ydata = ydata .* ypixdim;
0863     zdata = zdata .* zpixdim;
0864     aspect = [1 1 1];
0865 end
0866 
0867 if get(AVWVIEW.handles.coord,'value') == 3,    % meters
0868     xpixdim = xpixdim / 1000;
0869     ypixdim = ypixdim / 1000;
0870     zpixdim = zpixdim / 1000;
0871     xdata = xdata .* xpixdim;
0872     ydata = ydata .* ypixdim;
0873     zdata = zdata .* zpixdim;
0874     aspect = [1 1 1];
0875 end
0876 
0877 
0878 if isfield(AVWVIEW.handles,'axial_image'),
0879     set(AVWVIEW.handles.axial_axes,'Xlim',xdata);
0880     set(AVWVIEW.handles.axial_axes,'Ylim',ydata);
0881     set(AVWVIEW.handles.axial_axes,'Zlim',zdata);
0882     set(AVWVIEW.handles.axial_image,'Xdata',xdata);
0883     set(AVWVIEW.handles.axial_image,'Ydata',ydata);
0884     daspect(AVWVIEW.handles.axial_axes,aspect([1 2 3]));
0885 end;
0886 if isfield(AVWVIEW.handles,'coronal_image'),
0887     set(AVWVIEW.handles.coronal_axes,'Xlim',xdata);
0888     set(AVWVIEW.handles.coronal_axes,'Ylim',zdata);
0889     set(AVWVIEW.handles.coronal_axes,'Zlim',ydata);
0890     set(AVWVIEW.handles.coronal_image,'Xdata',xdata);
0891     set(AVWVIEW.handles.coronal_image,'Ydata',zdata);
0892     daspect(AVWVIEW.handles.coronal_axes,aspect([1 3 2]));
0893 end;
0894 if isfield(AVWVIEW.handles,'sagittal_image'),
0895     set(AVWVIEW.handles.sagittal_axes,'Xlim',ydata);
0896     set(AVWVIEW.handles.sagittal_axes,'Ylim',zdata);
0897     set(AVWVIEW.handles.sagittal_axes,'Zlim',xdata);
0898     set(AVWVIEW.handles.sagittal_image,'Xdata',ydata);
0899     set(AVWVIEW.handles.sagittal_image,'Ydata',zdata);
0900     daspect(AVWVIEW.handles.sagittal_axes,aspect([2 3 1]));
0901 end;
0902 
0903 set_display_values(AVWVIEW);
0904 AVWVIEW = set_crosshairs(AVWVIEW);
0905 
0906 return
0907 
0908 
0909 
0910 
0911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0912 function AVWVIEW = get_current_position(AVWVIEW),
0913 
0914 AVWVIEW = get_slider_position(AVWVIEW);
0915 [AVWVIEW, metric] = slices2metric(AVWVIEW);
0916 
0917 switch AVWVIEW.view,
0918     case 'sag',
0919         currentpoint = get(get(AVWVIEW.handles.sagittal_image,'Parent'),'CurrentPoint');
0920         metric.cor = currentpoint(1,1);
0921         metric.axi = currentpoint(1,2);
0922     case 'cor',
0923         currentpoint = get(get(AVWVIEW.handles.coronal_image,'Parent'),'CurrentPoint');
0924         metric.sag = currentpoint(2,1);
0925         metric.axi = currentpoint(2,2);
0926     case 'axi',
0927         currentpoint = get(get(AVWVIEW.handles.axial_image,'Parent'),'CurrentPoint');
0928         metric.sag = currentpoint(2,1);
0929         metric.cor = currentpoint(2,2);
0930 end
0931 
0932 AVWVIEW = metric2slices(AVWVIEW,metric);
0933 AVWVIEW = check_slices(AVWVIEW);
0934 
0935 return
0936 
0937 
0938 
0939 
0940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0941 function AVWVIEW = get_slider_position(AVWVIEW),
0942 
0943 [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi] = deal(0);
0944 
0945 if isfield(AVWVIEW.handles,'sagittal_slider'),
0946     if ishandle(AVWVIEW.handles.sagittal_slider),
0947         AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_slider,'Value'));
0948     end
0949 end
0950 if AVWVIEW.slices.sag == 0,
0951     if isfield(AVWVIEW.handles,'sagittal_sliderN'),
0952         if ishandle(AVWVIEW.handles.sagittal_sliderN),
0953             AVWVIEW.slices.sag = round(get(AVWVIEW.handles.sagittal_sliderN,'Value'));
0954         end
0955     end
0956 end
0957 
0958 if isfield(AVWVIEW.handles,'coronal_slider'),
0959     if ishandle(AVWVIEW.handles.coronal_slider),
0960         AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_slider,'Value'));
0961     end
0962 end
0963 if AVWVIEW.slices.cor == 0,
0964     if isfield(AVWVIEW.handles,'coronal_sliderN'),
0965         if ishandle(AVWVIEW.handles.coronal_sliderN),
0966             AVWVIEW.slices.cor = round(get(AVWVIEW.handles.coronal_sliderN,'Value'));
0967         end
0968     end
0969 end
0970 
0971 if isfield(AVWVIEW.handles,'axial_slider'),
0972     if ishandle(AVWVIEW.handles.axial_slider),
0973         AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_slider,'Value'));
0974     end
0975 end
0976 if AVWVIEW.slices.axi == 0,
0977     if isfield(AVWVIEW.handles,'axial_sliderN'),
0978         if ishandle(AVWVIEW.handles.axial_sliderN),
0979             AVWVIEW.slices.axi = round(get(AVWVIEW.handles.axial_sliderN,'Value'));
0980         end
0981     end
0982 end
0983 
0984 AVWVIEW = check_slices(AVWVIEW);
0985 
0986 return
0987 
0988 
0989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0990 function AVWVIEW = check_slices(AVWVIEW),
0991 
0992 adjust = 0;
0993 
0994 [ SagSize, CorSize, AxiSize ] = size(AVWVIEW.avw.img);
0995 
0996 if AVWVIEW.slices.sag > SagSize,
0997     AVWVIEW.slices.sag = SagSize;
0998     adjust = 1;
0999 end;
1000 if AVWVIEW.slices.sag < 1,
1001     AVWVIEW.slices.sag = 1;
1002     adjust = 1;
1003 end;
1004 if AVWVIEW.slices.cor > CorSize,
1005     AVWVIEW.slices.cor = CorSize;
1006     adjust = 1;
1007 end;
1008 if AVWVIEW.slices.cor < 1,
1009     AVWVIEW.slices.cor = 1;
1010     adjust = 1;
1011 end;
1012 if AVWVIEW.slices.axi > AxiSize,
1013     AVWVIEW.slices.axi = AxiSize;
1014     adjust = 1;
1015 end;
1016 if AVWVIEW.slices.axi < 1,
1017     AVWVIEW.slices.axi = 1;
1018     adjust = 1;
1019 end;
1020 
1021 if adjust,
1022     AVWVIEW = slices2metric(AVWVIEW);
1023 end
1024 
1025 return
1026 
1027 
1028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1029 function set_display_values(AVWVIEW),
1030 
1031 % get coordinates of selected voxel and the image intensity there
1032 
1033 sag = AVWVIEW.slices.sag;
1034 cor = AVWVIEW.slices.cor;
1035 axi = AVWVIEW.slices.axi;
1036 
1037 imgvalue = AVWVIEW.avw.img(sag,cor,axi);
1038 
1039 set(AVWVIEW.handles.imval,'String',sprintf('%7.2f',imgvalue));
1040 set(AVWVIEW.handles.imval,'Value',imgvalue);
1041 
1042 % Now update the image position text for the selected voxel
1043 
1044 [AVWVIEW, metric] = slices2metric(AVWVIEW);
1045 sag = metric.sag;
1046 cor = metric.cor;
1047 axi = metric.axi;
1048 
1049 string = sprintf('%7.3f %7.3f %7.3f',sag,cor,axi);
1050 
1051 set(AVWVIEW.handles.impos,'String',string);
1052 set(AVWVIEW.handles.impos,'Value',[sag,cor,axi]);
1053 
1054 return
1055 
1056 
1057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 function [AVWVIEW,metric] = slices2metric(AVWVIEW),
1059 
1060 AVWVIEW.imgXYZ.voxels = [AVWVIEW.slices.sag,AVWVIEW.slices.cor,AVWVIEW.slices.axi];
1061 AVWVIEW.imgXYZ.meters = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2meters;
1062 AVWVIEW.imgXYZ.mm     = AVWVIEW.imgXYZ.voxels .* AVWVIEW.scale2mm;
1063 
1064 coord_value = get(AVWVIEW.handles.coord,'value');
1065 
1066 if coord_value == 2,
1067     % using mm
1068     img_mm = AVWVIEW.imgXYZ.mm;
1069     metric.axi = img_mm(3);
1070     metric.cor = img_mm(2);
1071     metric.sag = img_mm(1);
1072 elseif coord_value == 3,
1073     % using meters
1074     img_meters = AVWVIEW.imgXYZ.meters;
1075     metric.axi = img_meters(3);
1076     metric.cor = img_meters(2);
1077     metric.sag = img_meters(1);
1078 else
1079     % voxels
1080     metric = AVWVIEW.slices;
1081 end;
1082 
1083 return
1084 
1085 
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 function AVWVIEW = metric2slices(AVWVIEW,metric),
1088 
1089 coord_value = get(AVWVIEW.handles.coord,'value');
1090 
1091 if coord_value == 2,
1092     % using mm
1093     xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2));
1094     ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3));
1095     zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4));
1096     AVWVIEW.slices.axi = round(metric.axi / zpix);
1097     AVWVIEW.slices.cor = round(metric.cor / ypix);
1098     AVWVIEW.slices.sag = round(metric.sag / xpix);
1099 elseif coord_value == 3,
1100     % using meters
1101     xpix = double(AVWVIEW.avw.hdr.dime.pixdim(2)) / 1000;
1102     ypix = double(AVWVIEW.avw.hdr.dime.pixdim(3)) / 1000;
1103     zpix = double(AVWVIEW.avw.hdr.dime.pixdim(4)) / 1000;
1104     AVWVIEW.slices.axi = round(metric.axi / zpix);
1105     AVWVIEW.slices.cor = round(metric.cor / ypix);
1106     AVWVIEW.slices.sag = round(metric.sag / xpix);
1107 else
1108     % voxels
1109     AVWVIEW.slices.axi = round(metric.axi);
1110     AVWVIEW.slices.cor = round(metric.cor);
1111     AVWVIEW.slices.sag = round(metric.sag);
1112 end;
1113 
1114 return
1115 
1116 
1117 
1118 
1119 
1120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1121 function AVWVIEW = init(avw,invarname),
1122 
1123 % try to keep track of the input struct
1124 if exist('invarname','var'),
1125     if ~isempty(invarname),
1126         AVWVIEW.invarname = invarname;
1127     else
1128         AVWVIEW.invarname = '';
1129     end
1130 else
1131     AVWVIEW.invarname = '';
1132 end
1133 
1134 % GUI General Parameters
1135 GUIwidth  = 150;
1136 GUIheight = 50;
1137 
1138 version = '[$Revision: 1.2 $]';
1139 name = sprintf('AVW View [v%s]',version(12:16));
1140 
1141 if isfield(avw,'fileprefix'),
1142     if ~isempty(avw.fileprefix),
1143         format = strcat('%+',sprintf('%d',length(avw.fileprefix)+1),'s');
1144         name = strcat(name,' - ',sprintf(format,avw.fileprefix));
1145     end
1146 end
1147 
1148 % The Zbuffer provides smooth slice animations (OpenGL is no good)
1149 GUI = figure('Name',name,'Tag','AVWVIEW','units','characters',...
1150     'BackingStore','off',...
1151     'NumberTitle','off','color',[0 0 0],...
1152     'MenuBar','figure','Position',[1 1 GUIwidth GUIheight],...
1153     'Renderer','zbuffer');
1154 
1155 movegui(GUI,'center');
1156 
1157 set(GUI,'KeyPressFcn','avw_view([],[],''keypress'');');
1158 
1159 AVWVIEW.gui = GUI;
1160 
1161 Font.FontName   = 'Helvetica';
1162 Font.FontUnits  = 'Pixels';
1163 Font.FontSize   = 9;
1164 Font.FontWeight = 'normal';
1165 Font.FontAngle  = 'normal';
1166 
1167 
1168 AVWVIEW.shading = 'flat';
1169 shading(AVWVIEW.shading)
1170 
1171 
1172 
1173 %     % determine the datatype of avw.img
1174 %     switch double(avw.hdr.dime.bitpix),
1175 %     case 1,
1176 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1177 %         avw.img = uint8(avw.img);
1178 %     case 8,
1179 %         fprintf('...converting avw.img to uint8 for viewing only.\n\n');
1180 %         avw.img = uint8(avw.img);
1181 %     case 16,
1182 %         fprintf('...converting avw.img to uint16 for viewing only.\n\n');
1183 %         avw.img = uint16(avw.img);
1184 %     case {32,64},
1185 %         % make sure it is double, not single
1186 %         avw.img = double(avw.img);
1187 %     otherwise,
1188 %         % do nothing, leave it as is
1189 %     end
1190 
1191 
1192 % calculate image stats
1193 intensityMean = mean(mean(mean(avw.img)));
1194 intensityMeanRobust = mean(mean(mean(avw.img(find(avw.img)))));
1195 intensityStdev = std(std(std(avw.img)));
1196 
1197 intensityMax = max(max(max(avw.img)));
1198 
1199 % try to adjust for large intensity extremes
1200 if intensityMax > 255,
1201     % got 16 bit data, at least
1202     adjust = 0.5;
1203 else
1204     adjust = 0.9;
1205 end
1206 %AVWVIEW.clim = [0 (intensityMeanRobust + (10 * intensityStdev)) ];
1207 AVWVIEW.clim = [0 (intensityMax * adjust)];
1208 
1209 
1210 
1211 AVWVIEW.xdim = size(avw.img,1);
1212 AVWVIEW.ydim = size(avw.img,2);
1213 AVWVIEW.zdim = size(avw.img,3);
1214 
1215 AVWVIEW.slices.sag = 1;
1216 AVWVIEW.slices.cor = 1;
1217 AVWVIEW.slices.axi = 1;
1218 if AVWVIEW.xdim > 1, AVWVIEW.slices.sag = floor(AVWVIEW.xdim/2); end
1219 if AVWVIEW.ydim > 1, AVWVIEW.slices.cor = floor(AVWVIEW.ydim/2); end
1220 if AVWVIEW.zdim > 1, AVWVIEW.slices.axi = floor(AVWVIEW.zdim/2); end
1221 
1222 % store the volume center for later reference when
1223 % calculating fiducial locations
1224 center = avw_center(avw);
1225 AVWVIEW.center = center.abs.voxels;
1226 
1227 % set the default origin at the center
1228 AVWVIEW.origin  = AVWVIEW.center;
1229 
1230 AVWVIEW.pixdim = double(avw.hdr.dime.pixdim(2:4));
1231 
1232 AVWVIEW.scale2mm     = AVWVIEW.pixdim;          % vol scale in mm
1233 AVWVIEW.scale2meters = AVWVIEW.pixdim ./ 1000;  % vol scale in meters
1234 AVWVIEW.daspect      = AVWVIEW.pixdim ./ min(AVWVIEW.pixdim);
1235 
1236 xPlotSize = 0.38;
1237 yPlotSize = 0.38;
1238 
1239 AVWVIEW.cmapString = 'gray';
1240 
1241 AVWVIEW.cmap = colormap(AVWVIEW.cmapString);
1242 
1243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 
1245 % Axial Slice
1246 if AVWVIEW.xdim > 1 & AVWVIEW.ydim > 1,
1247 
1248     handles.axial_subplot = subplot('position',[0.075 0.075 xPlotSize yPlotSize]);
1249 
1250     Saxial = squeeze(avw.img(:,:,AVWVIEW.slices.axi));
1251 
1252     %handles.axial_image = pcolor(double(Saxial)); colormap(gray); shading interp
1253     %pcolor(Saxial'); colormap(gray); shading flat
1254 
1255     %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(flipdim(gray,1)); colorbar
1256     %surf(avw.img(:,:,20)','edgecolor','none'); view(2); axis tight; colormap(gray)
1257     %image(avw.img(:,:,20)'); axis image; colormap(gray)
1258     %imagesc(avw.img(:,:,20)'); axis image; colormap(gray)
1259 
1260     %handles.axial_image = image('Cdata',Saxial','CDataMapping','scaled',...
1261     %    'XData',[0 xdim],'YData',[0 ydim]);
1262 
1263     handles.axial_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.ydim],Saxial',AVWVIEW.clim);
1264 
1265     handles.axial_axes = gca;
1266     set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1267         'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1268 
1269     title('Axial','Color',[1 1 1])
1270     ylabel('Y')
1271     xlabel('X')
1272     %xlabel('(Right <<) X (>> Left)'); % default radiological orientation for Analyze
1273     %xlabel('(Left <<) X (>> Right)')
1274 
1275     % This callback navigates with mouse button click
1276     set(handles.axial_image,'ButtonDownFcn','avw_view([],[],''axial_image'');');
1277 
1278     GUIheight = 0.46;
1279 
1280     if AVWVIEW.zdim > 1,
1281         slider_step(1) = 1/(AVWVIEW.zdim);
1282         slider_step(2) = 1/(AVWVIEW.zdim);
1283         handles.axial_slider = uicontrol('Parent',GUI,'Style','slider',...
1284             'Units','Normalized', Font, ...
1285             'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1286             'BusyAction','queue',...
1287             'TooltipString','Axial slice navigation',...
1288             'Min',1,'Max',AVWVIEW.zdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.axi,...
1289             'Callback','avw_view([],[],''axial_slider'');');
1290     end
1291     handles.axial_sliderN = uicontrol('Parent',GUI,'Style','text',...
1292         'Units','Normalized', Font, ...
1293         'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1294         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1295         'BusyAction','queue',...
1296         'TooltipString','Axial slice number',...
1297         'String',num2str(AVWVIEW.slices.axi),'Value',AVWVIEW.slices.axi);
1298     handles.axial_sliderT = uicontrol('Parent',GUI,'Style','text',...
1299         'Units','Normalized', Font, ...
1300         'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1301         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1302         'BusyAction','queue',...
1303         'TooltipString','Axial slice navigation',...
1304         'String','Axial');
1305 
1306     handles.axial_xlim = get(handles.axial_axes,'Xlim');
1307     handles.axial_ylim = get(handles.axial_axes,'Ylim');
1308     handles.axial_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.axial_ylim);
1309     handles.axial_yline = line('Ydata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Xdata',handles.axial_xlim);
1310     set(handles.axial_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1311     set(handles.axial_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1312 
1313 end
1314 
1315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1316 
1317 % Coronal Slice
1318 if AVWVIEW.xdim > 1 & AVWVIEW.zdim > 1,
1319 
1320     handles.coronal_subplot = subplot('position',[0.075 0.575 xPlotSize yPlotSize]);
1321 
1322     Scor = squeeze(avw.img(:,AVWVIEW.slices.cor,:));
1323     handles.coronal_image = imagesc([0,AVWVIEW.xdim],[0,AVWVIEW.zdim],Scor',AVWVIEW.clim);
1324 
1325     handles.coronal_axes = gca;
1326     set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1327         'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1328 
1329     %xlabel('(Left <<) X (>> Right)')
1330     %xlabel('(Right <<) X (>> Left)')
1331     xlabel('X')
1332     ylabel('Z')
1333     title('Coronal','Color',[1 1 1])
1334 
1335     % This callback navigates with left click
1336     set(handles.coronal_image,'ButtonDownFcn','avw_view([],[],''coronal_image'');');
1337 
1338     GUIheight = GUIheight - 0.04;
1339 
1340     if AVWVIEW.ydim > 1,
1341         slider_step(1) = 1/(AVWVIEW.ydim);
1342         slider_step(2) = 1/(AVWVIEW.ydim);
1343         handles.coronal_slider = uicontrol('Parent',GUI,'Style','slider',...
1344             'Units','Normalized', Font, ...
1345             'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1346             'BusyAction','queue',...
1347             'TooltipString','Coronal slice navigation',...
1348             'Min',1,'Max',AVWVIEW.ydim,'SliderStep',slider_step,'Value',AVWVIEW.slices.cor,...
1349             'Callback','avw_view([],[],''coronal_slider'');');
1350     end
1351     handles.coronal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1352         'Units','Normalized', Font, ...
1353         'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1354         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1355         'BusyAction','queue',...
1356         'TooltipString','Coronal slice number',...
1357         'String',num2str(AVWVIEW.slices.cor),'Value',AVWVIEW.slices.cor);
1358     handles.coronal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1359         'Units','Normalized', Font, ...
1360         'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1361         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1362         'BusyAction','queue',...
1363         'TooltipString','Coronal slice navigation',...
1364         'String','Coronal');
1365 
1366     handles.coronal_xlim = get(handles.coronal_axes,'Xlim');
1367     handles.coronal_ylim = get(handles.coronal_axes,'Ylim');
1368     handles.coronal_xline = line('Xdata',[AVWVIEW.slices.sag AVWVIEW.slices.sag],'Ydata',handles.coronal_ylim);
1369     handles.coronal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.coronal_xlim);
1370     set(handles.coronal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1371     set(handles.coronal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1372 
1373 end
1374 
1375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 
1377 % Sagittal Slice
1378 if AVWVIEW.ydim > 1 & AVWVIEW.zdim > 1,
1379 
1380     handles.sagittal_subplot = subplot('position',[0.575 0.575 xPlotSize yPlotSize]);
1381 
1382     Ssag = squeeze(avw.img(AVWVIEW.slices.sag,:,:));
1383     handles.sagittal_image = imagesc([0,AVWVIEW.ydim],[0,AVWVIEW.zdim],Ssag',AVWVIEW.clim);
1384 
1385     handles.sagittal_axes = gca;
1386     set(gca,'YDir','normal','XLimMode','manual','YLimMode','manual',...
1387         'ClimMode','manual','YColor',[1 1 1],'XColor',[1 1 1])
1388 
1389     xlabel('Y')
1390     ylabel('Z')
1391     title('Sagittal','Color',[1 1 1])
1392 
1393     % This callback navigates with mouse click
1394     set(handles.sagittal_image,'ButtonDownFcn','avw_view([],[],''sagittal_image'');');
1395 
1396     GUIheight = GUIheight - 0.04;
1397 
1398     if AVWVIEW.xdim > 1,
1399         slider_step(1) = 1/(AVWVIEW.xdim);
1400         slider_step(2) = 1/(AVWVIEW.xdim);
1401         handles.sagittal_slider = uicontrol('Parent',GUI,'Style','slider',...
1402             'Units','Normalized', Font, ...
1403             'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'center',...
1404             'BusyAction','queue',...
1405             'TooltipString','Sagittal slice navigation',...
1406             'Min',1,'Max',AVWVIEW.xdim,'SliderStep',slider_step,'Value',AVWVIEW.slices.sag,...
1407             'Callback','avw_view([],[],''sagittal_slider'');');
1408     end
1409     handles.sagittal_sliderN = uicontrol('Parent',GUI,'Style','text',...
1410         'Units','Normalized', Font, ...
1411         'Position',[.65 GUIheight .03 .03], 'HorizontalAlignment', 'center',...
1412         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1413         'BusyAction','queue',...
1414         'TooltipString','Sagittal slice number',...
1415         'String',num2str(AVWVIEW.slices.sag),'Value',AVWVIEW.slices.sag);
1416     handles.sagittal_sliderT = uicontrol('Parent',GUI,'Style','text',...
1417         'Units','Normalized', Font, ...
1418         'Position',[.70 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1419         'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],...
1420         'BusyAction','queue',...
1421         'TooltipString','Sagittal slice navigation',...
1422         'String','Sagittal');
1423 
1424     handles.sagittal_xlim = get(handles.sagittal_axes,'Xlim');
1425     handles.sagittal_ylim = get(handles.sagittal_axes,'Ylim');
1426     handles.sagittal_xline = line('Xdata',[AVWVIEW.slices.cor AVWVIEW.slices.cor],'Ydata',handles.sagittal_ylim);
1427     handles.sagittal_yline = line('Ydata',[AVWVIEW.slices.axi AVWVIEW.slices.axi],'Xdata',handles.sagittal_xlim);
1428     set(handles.sagittal_xline,'Color','b','EraseMode','xor','Tag','XLINE');
1429     set(handles.sagittal_yline,'Color','b','EraseMode','xor','Tag','YLINE');
1430 
1431 end
1432 
1433 
1434 
1435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1437 % Image Contex Menus
1438 
1439 menu=uicontextmenu;
1440 
1441 % enable right click access to ROI tools
1442 roi = uimenu(menu,'Label','ROI');
1443 uimenu(roi,'Label','ROI (9x9x9 block)','Callback','avw_view([],[],''roi_9'');');
1444 uimenu(roi,'Label','ROI (7x7x7 block)','Callback','avw_view([],[],''roi_7'');');
1445 uimenu(roi,'Label','ROI (5x5x5 block)','Callback','avw_view([],[],''roi_5'');');
1446 uimenu(roi,'Label','ROI (3x3x3 block)','Callback','avw_view([],[],''roi_3'');');
1447 
1448 % save image to graphics file
1449 uimenu(menu,'Label','Save Image','Callback','avw_view([],[],''save_image'');');
1450 
1451 % zoom image to new figure
1452 uimenu(menu,'Label','Zoom Image','Callback','avw_view([],[],''zoom'');');
1453 
1454 if isfield(handles,'axial_image'),
1455     if isempty(get(handles.axial_image,'uicontextmenu')),
1456         set(handles.axial_image,'uicontextmenu',menu);
1457     end
1458 end
1459 if isfield(handles,'coronal_image'),
1460     if isempty(get(handles.coronal_image,'uicontextmenu')),
1461         set(handles.coronal_image,'uicontextmenu',menu);
1462     end
1463 end
1464 if isfield(handles,'sagittal_image'),
1465     if isempty(get(handles.sagittal_image,'uicontextmenu')),
1466         set(handles.sagittal_image,'uicontextmenu',menu);
1467     end
1468 end
1469 
1470 
1471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1473 
1474 % Image Intensity at Mouse Click
1475 
1476 GUIheight = GUIheight - 0.04;
1477 
1478 handles.Timval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1479     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1480     'BackgroundColor', [0 0 0],...
1481     'ForegroundColor', [1 1 1],...
1482     'BusyAction','queue',...
1483     'String','Image Intensity');
1484 handles.imval = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1485     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1486     'BackgroundColor', [0 0 0],...
1487     'ForegroundColor', [1 1 1],...
1488     'BusyAction','queue',...
1489     'String','x','Value',0);
1490 
1491 % Image Position at Mouse Click
1492 
1493 GUIheight = GUIheight - 0.04;
1494 
1495 handles.Timpos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1496     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1497     'BackgroundColor', [0 0 0],...
1498     'ForegroundColor', [1 1 1],...
1499     'BusyAction','queue',...
1500     'String','Image Position');
1501 handles.impos = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1502     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1503     'BackgroundColor', [0 0 0],...
1504     'ForegroundColor', [1 1 1],...
1505     'BusyAction','queue',...
1506     'String','xyz','Value',[0 0 0]);
1507 
1508 
1509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1511 
1512 GUIheight = GUIheight - 0.04;
1513 
1514 handles.flip = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1515     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1516     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1517     'BusyAction','queue',...
1518     'TooltipString','Flip Left and Right (viewer only, see also avw_flip).',...
1519     'String','Flip L/R',...
1520     'Callback','avw_view([],[],''flip'');');
1521 handles.flipStatus = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1522     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1523     'BackgroundColor', [0 0 0],...
1524     'ForegroundColor', [1 1 1],...
1525     'BusyAction','queue',...
1526     'TooltipString','Flipped Status',...
1527     'String','R>>L (radiological)');
1528 
1529 
1530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532 
1533 % AC Location
1534 
1535 GUIheight = GUIheight - 0.04;
1536 
1537 handles.Tac = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1538     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1539     'BackgroundColor', [.3 .3 .3],...
1540     'ForegroundColor', [1 1 1],...
1541     'BusyAction','queue',...
1542     'TooltipString','AC point in (voxels) or (meter offset from center of volume)',...
1543     'String','AC Point',...
1544     'Callback','avw_view([],[],''ac'');');
1545 handles.ac = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1546     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1547     'BackgroundColor', [0 0 0],...
1548     'ForegroundColor', [1 1 1],...
1549     'BusyAction','queue',...
1550     'TooltipString','These values are offset from volume center.',...
1551     'String','x,y,z');
1552 
1553 % Nasion Location
1554 
1555 GUIheight = GUIheight - 0.04;
1556 
1557 handles.Tnasion = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1558     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1559     'BackgroundColor', [.3 .3 .3],...
1560     'ForegroundColor', [1 1 1],...
1561     'BusyAction','queue',...
1562     'TooltipString','Update Nasion - should be toward +Y',...
1563     'String','Fiducial: Nas',...
1564     'Callback','avw_view([],[],''nasion'');');
1565 handles.nasion = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1566     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1567     'BackgroundColor', [0 0 0],...
1568     'ForegroundColor', [1 1 1],...
1569     'BusyAction','queue',...
1570     'TooltipString','These values are offset from volume center, should be toward +Y',...
1571     'String','x,y,z');
1572 
1573 % Right Preauricular Location
1574 
1575 GUIheight = GUIheight - 0.04;
1576 
1577 handles.Trpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1578     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1579     'BackgroundColor', [.3 .3 .3],...
1580     'ForegroundColor', [1 1 1],...
1581     'BusyAction','queue',...
1582     'TooltipString','Update Right Preauricular - should be toward -X',...
1583     'String','Fiducial: RPA',...
1584     'Callback','avw_view([],[],''rpa'');');
1585 handles.rpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1586     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1587     'BackgroundColor', [0 0 0],...
1588     'ForegroundColor', [1 1 1],...
1589     'BusyAction','queue',...
1590     'TooltipString','These values are offset from volume center, should be toward -X',...
1591     'String','x,y,z');
1592 
1593 % Left Preauricular Location
1594 
1595 GUIheight = GUIheight - 0.04;
1596 
1597 handles.Tlpa = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1598     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1599     'BackgroundColor', [.3 .3 .3],...
1600     'ForegroundColor', [1 1 1],...
1601     'BusyAction','queue',...
1602     'TooltipString','Update Left Preauricular - should be toward +X',...
1603     'String','Fiducial: LPA',...
1604     'Callback','avw_view([],[],''lpa'');');
1605 handles.lpa = uicontrol('Parent',GUI,'Style','text','Units','Normalized', Font, ...
1606     'Position',[.65 GUIheight .15 .03], 'HorizontalAlignment', 'right',...
1607     'BackgroundColor', [0 0 0],...
1608     'ForegroundColor', [1 1 1],...
1609     'BusyAction','queue',...
1610     'TooltipString','These values are offset from volume center, should be toward +X',...
1611     'String','x,y,z');
1612 
1613 
1614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1616 
1617 GUIheight = GUIheight - 0.04;
1618 
1619 handles.contrast = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1620     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1621     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1622     'BusyAction','queue',...
1623     'TooltipString','Auto contrast with gray colormap',...
1624     'String','Auto Contrast',...
1625     'Callback','avw_view([],[],''contrast'');');
1626 
1627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1629 
1630 GUIheight = GUIheight - 0.04;
1631 
1632 handles.dimmer = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1633     'Position',[.55 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1634     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1635     'BusyAction','queue',...
1636     'TooltipString','Dim by 1%',...
1637     'String','Dimmer',...
1638     'Callback','avw_view([],[],''dimmer'');');
1639 
1640 handles.brighter = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1641     'Position',[.65 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1642     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1643     'BusyAction','queue',...
1644     'TooltipString','Brighten by 1%',...
1645     'String','Brighter',...
1646     'Callback','avw_view([],[],''brighter'');');
1647 
1648 handles.clim = uicontrol('Parent',GUI,'Style','edit','Units','Normalized', Font, ...
1649     'Position',[.75 GUIheight .06 .03], 'HorizontalAlignment', 'right',...
1650     'BackgroundColor', [0 0 0],...
1651     'ForegroundColor', [1 1 1],...
1652     'BusyAction','queue',...
1653     'TooltipString','Image intensity Climit (inverse brightness)',...
1654     'String',num2str(AVWVIEW.clim(2)),...
1655     'Callback','avw_view([],[],''setClimit'');');
1656 
1657 handles.cmap = uicontrol('Parent',GUI,'Style','popup','Units','Normalized', Font, ...
1658     'Position',[.82 GUIheight .06 .03], 'HorizontalAlignment', 'left',...
1659     'BackgroundColor', [0 0 0],...
1660     'ForegroundColor', [1 1 1],...
1661     'BusyAction','queue',...
1662     'TooltipString','Color Map',...
1663     'String',{'gray','bone','copper','hot','cool','spring','summer','autumn','winter','hsv','jet'},...
1664     'Callback','avw_view([],[],''setCmap'');');
1665 
1666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1668 
1669 GUIheight = 0.46;
1670 
1671 handles.crosshairs = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
1672     'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1673     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1674     'BusyAction','queue',...
1675     'TooltipString','Toggle Crosshairs on/off',...
1676     'String','Crosshairs','Value',1,...
1677     'Callback','avw_view([],[],''crosshairs'');');
1678 
1679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1681 
1682 GUIheight = GUIheight - 0.04;
1683 
1684 handles.histogram = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1685     'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1686     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1687     'BusyAction','queue',...
1688     'TooltipString','Histogram of Volume Intensity',...
1689     'String','Histogram',...
1690     'Callback','avw_view([],[],''histogram'');');
1691 
1692 
1693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1695 
1696 GUIheight = GUIheight - 0.04;
1697 
1698 handles.coord = uicontrol('Parent',GUI,'Style','popupmenu','Units','Normalized', Font, ...
1699     'Position',[.85 GUIheight .10 .03], 'HorizontalAlignment', 'left',...
1700     'BackgroundColor', [.3 .3 .3],'ForegroundColor', [1 1 1],...
1701     'BusyAction','queue',...
1702     'TooltipString','Voxel or Mensurated Axis Coordinates',...
1703     'String',{'Voxels','mm','meters'},...
1704     'Callback','avw_view([],[],''coordinates'');');
1705 
1706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1708 
1709 Font.FontWeight = 'bold';
1710 
1711 % View avw.hdr
1712 handles.Bhdr = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1713     'Position',[.92 .05 .07 .03],...
1714     'String','HDR','BusyAction','queue',...
1715     'TooltipString','View the .hdr parameters.',...
1716     'BackgroundColor',[0.0 0.0 0.5],...
1717     'ForegroundColor',[1 1 1], 'HorizontalAlignment', 'center',...
1718     'Callback',strcat('AVWVIEW = get(gcbf,''Userdata''); ',...
1719     'avw_view_hdr(AVWVIEW.avw,AVWVIEW.gui);',...
1720     'clear AVWVIEW;'));
1721 
1722 % OK: Return the avw!
1723 handles.Bquit = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
1724     'Position',[.92 .01 .07 .03],...
1725     'String','RETURN','BusyAction','queue',...
1726     'BackgroundColor',[0.0 0.5 0.0],...
1727     'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
1728     'Callback','avw_view([],[],''quit'');');
1729 
1730 % Update the gui_struct handles for this gui
1731 if exist('parent','var'), AVWVIEW.parent.gui = parent; end
1732 AVWVIEW.avw = avw;
1733 AVWVIEW.handles = handles;
1734 set(AVWVIEW.gui,'Userdata',AVWVIEW);
1735 set(AVWVIEW.gui,'HandleVisibility','callback');
1736 
1737 return
1738 
1739 
1740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1741 function slice_img(avw),
1742 
1743 figure
1744 xslice = 128;
1745 slice = squeeze( avw.img(xslice,:,:) );
1746 imagesc(slice); axis image; colormap('gray')
1747 figure
1748 yslice = 128;
1749 slice = squeeze( avw.img(:,yslice,:) );
1750 imagesc(slice); axis image; colormap('gray')
1751 figure
1752 zslice = 128;
1753 slice = squeeze( avw.img(:,:,zslice) );
1754 imagesc(slice); axis image; colormap('gray')
1755 
1756 return

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