Home > marsbar > mars_orthviews.m

mars_orthviews

PURPOSE ^

Display Orthogonal Views of a Normalized Image

SYNOPSIS ^

function varargout = mars_orthviews(action,varargin)

DESCRIPTION ^

 Display Orthogonal Views of a Normalized Image
 MarsBaR version of spm_orthviews with very minor modifications 
 FORMAT H = mars_orthviews('Image',filename[,position])
 filename - name of image to display
 area     - position of image
            -  area(1) - position x
            -  area(2) - position y
            -  area(3) - size x
            -  area(4) - size y
 H        - handle for ortho sections
 FORMAT mars_orthviews('BB',bb)
 bb       - bounding box
            [loX loY loZ
             hiX hiY hiZ]

 FORMAT mars_orthviews('Redraw')
 Redraws the images

 FORMAT mars_orthviews('Reposition',centre)
 centre   - X, Y & Z coordinates of centre voxel

 FORMAT mars_orthviews('Space'[,handle])
 handle   - the view to define the space by
 with no arguments - puts things into mm space

 FORMAT mars_orthviews('MaxBB')
 sets the bounding box big enough display the whole of all images

 FORMAT mars_orthviews('Resolution',res)
 res      - resolution (mm)

 FORMAT mars_orthviews('Delete', handle)
 handle   - image number to delete

 FORMAT mars_orthviews('Reset')
 clears the orthogonal views

 FORMAT mars_orthviews('Pos')
 returns the co-ordinate of the crosshairs in millimetres in the
 standard space.

 FORMAT mars_orthviews('Pos', i)
 returns the voxel co-ordinate of the crosshairs in the image in the
 ith orthogonal section.

 FORMAT mars_orthviews('Xhairs','off') OR mars_orthviews('Xhairs')
 disables the cross-hairs on the display.

 FORMAT mars_orthviews('Xhairs','on')
 enables the cross-hairs.

 FORMAT mars_orthviews('Interp',hld)
 sets the hold value to hld (see spm_slice_vol).

 FORMAT mars_orthviews('AddBlobs',handle,XYZ,Z,mat)
 Adds blobs from a pointlist to the image specified by the handle(s).
 handle   - image number to add blobs to
 XYZ      - blob voxel locations (currently in millimeters)
 Z        - blob voxel intensities
 mat      - matrix from millimeters to voxels of blob.
 This method only adds one set of blobs, and displays them using a
 split colour table.

 mars_orthviews('AddColouredBlobs',handle,XYZ,Z,mat,colour)
 Adds blobs from a pointlist to the image specified by the handle(s).
 handle   - image number to add blobs to
 XYZ      - blob voxel locations (currently in millimeters)
 Z        - blob voxel intensities
 mat      - matrix from millimeters to voxels of blob.
 colour   - the 3 vector containing the colour that the blobs should be
 Several sets of blobs can be added in this way, and it uses full colour.
 Although it may not be particularly attractive on the screen, the colour
 blobs print well.

 mars_orthviews('AddColouredMatrix',handle,matrix,mat,colour)
 Adds blobs from a matrix to the image specified by the handle(s).
 handle   - image number to add blobs to
 matrix   - voxel matrix
 mat      - matrix from matrix coordinates to millimeters 
 colour   - the 3 vector containing the colour that the blobs should be

 FORMAT mars_orthviews('RemoveBlobs',handle)
 Removes all blobs from the image specified by the handle(s).

 mars_orthviews('Register',hReg)
 hReg      - Handle of HandleGraphics object to build registry in.
 See spm_XYZreg for more information.

_______________________________________________________________________
 @(#)mars_orthviews.m    2.25 John Ashburner & Matthew Brett 01/03/19

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = mars_orthviews(action,varargin)
0002 % Display Orthogonal Views of a Normalized Image
0003 % MarsBaR version of spm_orthviews with very minor modifications
0004 % FORMAT H = mars_orthviews('Image',filename[,position])
0005 % filename - name of image to display
0006 % area     - position of image
0007 %            -  area(1) - position x
0008 %            -  area(2) - position y
0009 %            -  area(3) - size x
0010 %            -  area(4) - size y
0011 % H        - handle for ortho sections
0012 % FORMAT mars_orthviews('BB',bb)
0013 % bb       - bounding box
0014 %            [loX loY loZ
0015 %             hiX hiY hiZ]
0016 %
0017 % FORMAT mars_orthviews('Redraw')
0018 % Redraws the images
0019 %
0020 % FORMAT mars_orthviews('Reposition',centre)
0021 % centre   - X, Y & Z coordinates of centre voxel
0022 %
0023 % FORMAT mars_orthviews('Space'[,handle])
0024 % handle   - the view to define the space by
0025 % with no arguments - puts things into mm space
0026 %
0027 % FORMAT mars_orthviews('MaxBB')
0028 % sets the bounding box big enough display the whole of all images
0029 %
0030 % FORMAT mars_orthviews('Resolution',res)
0031 % res      - resolution (mm)
0032 %
0033 % FORMAT mars_orthviews('Delete', handle)
0034 % handle   - image number to delete
0035 %
0036 % FORMAT mars_orthviews('Reset')
0037 % clears the orthogonal views
0038 %
0039 % FORMAT mars_orthviews('Pos')
0040 % returns the co-ordinate of the crosshairs in millimetres in the
0041 % standard space.
0042 %
0043 % FORMAT mars_orthviews('Pos', i)
0044 % returns the voxel co-ordinate of the crosshairs in the image in the
0045 % ith orthogonal section.
0046 %
0047 % FORMAT mars_orthviews('Xhairs','off') OR mars_orthviews('Xhairs')
0048 % disables the cross-hairs on the display.
0049 %
0050 % FORMAT mars_orthviews('Xhairs','on')
0051 % enables the cross-hairs.
0052 %
0053 % FORMAT mars_orthviews('Interp',hld)
0054 % sets the hold value to hld (see spm_slice_vol).
0055 %
0056 % FORMAT mars_orthviews('AddBlobs',handle,XYZ,Z,mat)
0057 % Adds blobs from a pointlist to the image specified by the handle(s).
0058 % handle   - image number to add blobs to
0059 % XYZ      - blob voxel locations (currently in millimeters)
0060 % Z        - blob voxel intensities
0061 % mat      - matrix from millimeters to voxels of blob.
0062 % This method only adds one set of blobs, and displays them using a
0063 % split colour table.
0064 %
0065 % mars_orthviews('AddColouredBlobs',handle,XYZ,Z,mat,colour)
0066 % Adds blobs from a pointlist to the image specified by the handle(s).
0067 % handle   - image number to add blobs to
0068 % XYZ      - blob voxel locations (currently in millimeters)
0069 % Z        - blob voxel intensities
0070 % mat      - matrix from millimeters to voxels of blob.
0071 % colour   - the 3 vector containing the colour that the blobs should be
0072 % Several sets of blobs can be added in this way, and it uses full colour.
0073 % Although it may not be particularly attractive on the screen, the colour
0074 % blobs print well.
0075 %
0076 % mars_orthviews('AddColouredMatrix',handle,matrix,mat,colour)
0077 % Adds blobs from a matrix to the image specified by the handle(s).
0078 % handle   - image number to add blobs to
0079 % matrix   - voxel matrix
0080 % mat      - matrix from matrix coordinates to millimeters
0081 % colour   - the 3 vector containing the colour that the blobs should be
0082 %
0083 % FORMAT mars_orthviews('RemoveBlobs',handle)
0084 % Removes all blobs from the image specified by the handle(s).
0085 %
0086 % mars_orthviews('Register',hReg)
0087 % hReg      - Handle of HandleGraphics object to build registry in.
0088 % See spm_XYZreg for more information.
0089 %
0090 %_______________________________________________________________________
0091 % @(#)mars_orthviews.m    2.25 John Ashburner & Matthew Brett 01/03/19
0092 %
0093 % $Id$
0094 
0095 
0096 % The basic fields of st are:
0097 %         n        - the number of images currently being displayed
0098 %         vols     - a cell array containing the data on each of the
0099 %                    displayed images.
0100 %         Space    - a mapping between the displayed images and the
0101 %                    mm space of each image.
0102 %         bb       - the bounding box of the displayed images.
0103 %         centre   - the current centre of the orthogonal views
0104 %         callback - a callback to be evaluated on a button-click.
0105 %         xhairs   - crosshairs off/on
0106 %         hld      - the interpolation method
0107 %         fig      - the figure that everything is displayed in
0108 %         mode     - the position/orientation of the sagittal view.
0109 %                    - currently always 1
0110 %
0111 %         st.registry.hReg \_ See spm_XYZreg for documentation
0112 %         st.registry.hMe  /
0113 %
0114 % For each of the displayed images, there is a non-empty entry in the
0115 % vols cell array.  Handles returned by "mars_orthviews('Image',.....)"
0116 % indicate the position in the cell array of the newly created ortho-view.
0117 % Operations on each ortho-view require the handle to be passed.
0118 %
0119 % When a new image is displayed, the cell entry contains the information
0120 % returned by spm_vol (type help spm_vol for more info).  In addition,
0121 % there are a few other fields, some of which I will document here:
0122 %
0123 %         premul - a matrix to premultiply the .mat field by.  Useful
0124 %                  for re-orienting images.
0125 %         window - either 'auto' or an intensity range to display the
0126 %                  image with.
0127 %
0128 %         ax     - a cell array containing an element for the three
0129 %                  views.  The fields of each element are handles for
0130 %                  the axis, image and crosshairs.
0131 %
0132 %         blobs - optional.  Is there for using to superimpose blobs.
0133 %                 vol     - 3D array of image data
0134 %                 mat     - a mapping from vox-to-mm (see spm_vol, or
0135 %                           help on image formats).
0136 %                 max     - maximum intensity for scaling to.  If it
0137 %                           does not exist, then images are auto-scaled.
0138 %
0139 %                 There are two colouring modes: full colour, and split
0140 %                 colour.  When using full colour, there should be a
0141 %                 'colour' field for each cell element.  When using
0142 %                 split colourscale, there is a handle for the colorbar
0143 %                 axis.
0144 %
0145 %                 colour  - if it exists it contains the
0146 %                           red,green,blue that the blobs should be
0147 %                           displayed in.
0148 %                 cbar    - handle for colorbar (for split colourscale).
0149 
0150 global st;
0151 
0152 if isempty(st), reset_st; end;
0153 
0154 spm('Pointer','watch');
0155 
0156 if nargin == 0, action = ''; end;
0157 action = lower(action);
0158 
0159 switch lower(action),
0160 case 'image',
0161     H = specify_image(varargin{1});
0162     if ~isempty(H)
0163         if length(varargin)>=2, st.vols{H}.area = varargin{2}; end;
0164         if isempty(st.bb), st.bb = maxbb; end;
0165         bbox;
0166         redraw(H);
0167     end;
0168     varargout{1} = H;
0169 
0170 case 'bb',
0171     if length(varargin)> 0 & all(size(varargin{1})==[2 3]), st.bb = varargin{1}; end;
0172     bbox;
0173     redraw_all;
0174 
0175 case 'redraw',
0176     redraw_all;
0177     eval(st.callback);
0178     if isfield(st,'registry'),
0179         spm_XYZreg('SetCoords',st.centre,st.registry.hReg,st.registry.hMe);
0180     end;
0181 
0182 case 'reposition',
0183     if length(varargin)<1, tmp = findcent;
0184     else, tmp = varargin{1}; end;
0185     if length(tmp)==3, st.centre = tmp(:); end;
0186     redraw_all;
0187     eval(st.callback);
0188     if isfield(st,'registry'),
0189         spm_XYZreg('SetCoords',st.centre,st.registry.hReg,st.registry.hMe);
0190     end;
0191 
0192 case 'setcoords',
0193     st.centre = varargin{1};
0194     st.centre = st.centre(:);
0195     redraw_all;
0196     eval(st.callback);
0197 
0198 case 'space',
0199     if length(varargin)<1,
0200         st.Space = eye(4);
0201         st.bb = maxbb;
0202         redraw_all;
0203     else,
0204         space(varargin{1});
0205         redraw_all;
0206     end;
0207     bbox;
0208 
0209 case 'maxbb',
0210     st.bb = maxbb;
0211     bbox;
0212     redraw_all;
0213 
0214 case 'resolution',
0215     resolution(varargin{1});
0216     bbox;
0217     redraw_all;
0218 
0219 case 'window',
0220     if length(varargin)<2,
0221         win = 'auto';
0222     elseif length(varargin{2})==2,
0223         win = varargin{2};
0224     end;
0225     for i=valid_handles(varargin{1}),
0226         st.vols{i}.window = win;
0227     end;
0228     redraw(varargin{1});
0229 
0230 case 'delete',
0231     my_delete(varargin{1});
0232 
0233 case 'move',
0234     move(varargin{1},varargin{2});
0235     % redraw_all;
0236 
0237 case 'reset',
0238     my_reset;
0239 
0240 case 'pos',
0241     if isempty(varargin),
0242         H = st.centre(:);
0243     else,
0244         H = pos(varargin{1});
0245     end;
0246     varargout{1} = H;
0247 
0248 case 'interp',
0249     st.hld = varargin{1};
0250     redraw_all;
0251 
0252 case 'xhairs',
0253     xhairs(varargin{1});
0254 
0255 case 'register',
0256     register(varargin{1});
0257 
0258 case 'addblobs',
0259     addblobs(varargin{1}, varargin{2},varargin{3},varargin{4});
0260     redraw(varargin{1});
0261 
0262 case 'addcolouredblobs',
0263     addcolouredblobs(varargin{1}, varargin{2},varargin{3},varargin{4},varargin{5});
0264 
0265 case 'addcolouredmatrix',
0266     addcolouredmatrix(varargin{1}, varargin{2},varargin{3},varargin{4});
0267 
0268 case 'addimage',
0269     addimage(varargin{1}, varargin{2});
0270     redraw(varargin{1});
0271 
0272 case 'addcolouredimage',
0273     addcolouredimage(varargin{1}, varargin{2},varargin{3});
0274  
0275 case 'addtruecolourimage',
0276  % mars_orthviews('Addtruecolourimage',handle,filename,colourmap,prop,mx,mn)
0277  % Adds blobs from an image in true colour
0278  % handle   - image number to add blobs to [default 1]
0279  % filename of image containing blob data [default - request via GUI]
0280  % colourmap - colormap to display blobs in [GUI input]
0281  % prop - intensity proportion of activation cf grayscale [0.4]
0282  % mx   - maximum intensity to scale to [maximum value in activation image]
0283  % mn   - minimum intensity to scale to [minimum value in activation image]
0284  %
0285  
0286  % For selecting images, later
0287 img_flt = mars_veropts('get_img_ext');
0288 
0289  if nargin < 2
0290    varargin(1) = {1};
0291  end
0292  if nargin < 3
0293    varargin(2) = {spm_get(1, img_flt, 'Image with activation signal')};
0294  end
0295  if ischar(varargin{2}),varargin{2} = spm_vol(varargin{2});end
0296  if nargin < 4
0297    actc = [];
0298    while isempty(actc)
0299      actc = getcmap(spm_input('Colourmap for activation image', '+1','s'));
0300    end
0301    varargin(3) = {actc};
0302  end
0303  if nargin < 5
0304    varargin(4) = {0.4};
0305  end
0306  if nargin < 6
0307    varargin(5) = {max([eps maxval(varargin{2})])};
0308  end
0309  if nargin < 7
0310    varargin(6) = {min([0 minval(varargin{2})])};
0311  end
0312 
0313  addtruecolourimage(varargin{1}, varargin{2},varargin{3}, varargin{4}, ...
0314             varargin{5}, varargin{6});
0315  redraw(varargin{1});
0316 
0317 case 'rmblobs',
0318     rmblobs(varargin{1});
0319     redraw(varargin{1});
0320 
0321 otherwise,
0322     warning('Unknown action string')
0323 end;
0324 
0325 spm('Pointer');
0326 return;
0327 
0328 
0329 %_______________________________________________________________________
0330 %_______________________________________________________________________
0331 function addblobs(handle, xyz, t, mat)
0332 global st
0333 for i=valid_handles(handle),
0334     if ~isempty(xyz),
0335         rcp      = round(xyz);
0336         dim      = max(rcp,[],2)';
0337         off      = rcp(1,:) + dim(1)*(rcp(2,:)-1 + dim(2)*(rcp(3,:)-1));
0338         vol      = zeros(dim)+NaN;
0339         vol(off) = t;
0340         vol      = reshape(vol,dim);
0341         st.vols{i}.blobs=cell(1,1);
0342         if st.mode == 0,
0343             axpos = get(st.vols{i}.ax{2}.ax,'Position');
0344         else,
0345             axpos = get(st.vols{i}.ax{1}.ax,'Position');
0346         end;
0347         ax = axes('Parent',st.fig,'Position',[(axpos(1)+axpos(3)+0.1) (axpos(2)+0.005) 0.05 (axpos(4)-0.01)],...
0348             'Box','on');
0349         mx = max([eps max(t)]);
0350         mn = min([0 min(t)]);
0351         image([0 1],[mn mx],[1:64]' + 64,'Parent',ax);
0352         set(ax,'YDir','normal','XTickLabel',[]);
0353         st.vols{i}.blobs{1} = struct('vol',vol,'mat',mat,'cbar',ax,'max',mx, 'min',mn);
0354     end;
0355 end;
0356 return;
0357 %_______________________________________________________________________
0358 %_______________________________________________________________________
0359 function addimage(handle, fname)
0360 global st
0361 for i=valid_handles(handle),
0362     vol = spm_vol(fname);
0363     mat = vol.mat;
0364     st.vols{i}.blobs=cell(1,1);
0365     if st.mode == 0,
0366         axpos = get(st.vols{i}.ax{2}.ax,'Position');
0367     else,
0368         axpos = get(st.vols{i}.ax{1}.ax,'Position');
0369     end;
0370     ax = axes('Parent',st.fig,'Position',[(axpos(1)+axpos(3)+0.05) (axpos(2)+0.005) 0.05 (axpos(4)-0.01)],...
0371         'Box','on');
0372     mx = max([eps maxval(vol)]);
0373     mn = min([0 minval(vol)]);
0374     image([0 1],[mn mx],[1:64]' + 64,'Parent',ax);
0375     set(ax,'YDir','normal','XTickLabel',[]);
0376     st.vols{i}.blobs{1} = struct('vol',vol,'mat',mat,'cbar',ax,'max',mx);
0377 end;
0378 return;
0379 %_______________________________________________________________________
0380 %_______________________________________________________________________
0381 function addcolouredblobs(handle, xyz, t, mat,colour)
0382 global st
0383 for i=valid_handles(handle),
0384     if ~isempty(xyz),
0385         rcp      = round(xyz);
0386         dim      = max(rcp,[],2)';
0387         off      = rcp(1,:) + dim(1)*(rcp(2,:)-1 + dim(2)*(rcp(3,:)-1));
0388         vol      = zeros(dim)+NaN;
0389         vol(off) = t;
0390         vol      = reshape(vol,dim);
0391         if ~isfield(st.vols{i},'blobs'),
0392             st.vols{i}.blobs=cell(1,1);
0393             bset = 1;
0394         else,
0395             bset = length(st.vols{i}.blobs)+1;
0396         end;
0397         axpos = get(st.vols{i}.ax{2}.ax,'Position');
0398         mx = max([eps maxval(vol)]);
0399         mn = min([0 minval(vol)]);
0400         st.vols{i}.blobs{bset} = struct('vol',vol,'mat',mat,'max',mx,'min',mn,'colour',colour);
0401     end;
0402 end;
0403 return;
0404 %_______________________________________________________________________
0405 %_______________________________________________________________________
0406 function addcolouredmatrix(handle, vol, mat,colour)
0407 global st
0408 for i=valid_handles(handle),
0409     if ~isempty(vol),
0410       if ~isfield(st.vols{i},'blobs'),
0411         st.vols{i}.blobs=cell(1,1);
0412         bset = 1;
0413       else,
0414         bset = length(st.vols{i}.blobs)+1;
0415       end;
0416       axpos = get(st.vols{i}.ax{2}.ax,'Position');
0417       mx = max([eps maxval(vol)]);
0418       mn = min([0 minval(vol)]);
0419       st.vols{i}.blobs{bset} = struct('vol',vol,'mat',mat,'max',mx,'min',mn,'colour',colour);
0420     end;
0421 end;
0422 return;
0423 %_______________________________________________________________________
0424 %_______________________________________________________________________
0425 function addcolouredimage(handle, fname,colour)
0426 global st
0427 for i=valid_handles(handle),
0428 
0429     vol = spm_vol(fname);
0430     mat = vol.mat;
0431     if ~isfield(st.vols{i},'blobs'),
0432         st.vols{i}.blobs=cell(1,1);
0433         bset = 1;
0434     else,
0435         bset = length(st.vols{i}.blobs)+1;
0436     end;
0437     axpos = get(st.vols{i}.ax{2}.ax,'Position');
0438     mx = max([eps maxval(vol)]);
0439     mn = min([0 minval(vol)]);
0440     st.vols{i}.blobs{bset} = struct('vol',vol,'mat',mat,'max',mx,'min',mn,'colour',colour);
0441 end;
0442 return;
0443 %_______________________________________________________________________
0444 %_______________________________________________________________________
0445 function addtruecolourimage(handle,vol,colourmap,prop,mx,mn)
0446 % adds true colour image to current displayed image
0447 global st
0448 mat = vol.mat;
0449 if isstruct(vol) & isfield(vol, 'vol'), vol = vol.vol;end
0450 for i=valid_handles(handle),
0451   if ~isfield(st.vols{i},'blobs'),
0452     st.vols{i}.blobs=cell(1,1);
0453     bset = 1;
0454   else,
0455     bset = length(st.vols{i}.blobs)+1;
0456   end;
0457 % axpos = get(st.vols{i}.ax{2}.ax,'Position');
0458   c = struct('cmap', colourmap,'prop',prop);
0459   st.vols{i}.blobs{bset} = struct('vol',vol,'mat',mat,'max',mx,'min',mn,'colour',c);
0460 end;
0461 return;
0462 %_______________________________________________________________________
0463 %_______________________________________________________________________
0464 function rmblobs(handle)
0465 global st
0466 for i=valid_handles(handle),
0467     if isfield(st.vols{i},'blobs'),
0468         for j=1:length(st.vols{i}.blobs),
0469             if isfield(st.vols{i}.blobs{j},'cbar') & ishandle(st.vols{i}.blobs{j}.cbar),
0470                 delete(st.vols{i}.blobs{j}.cbar);
0471             end;
0472         end;
0473         st.vols{i} = rmfield(st.vols{i},'blobs');
0474     end;
0475 end;
0476 return;
0477 %_______________________________________________________________________
0478 %_______________________________________________________________________
0479 function register(hreg)
0480 global st
0481 tmp = uicontrol('Position',[0 0 1 1],'Visible','off','Parent',st.fig);
0482 h   = valid_handles(1:24);
0483 if ~isempty(h),
0484     tmp = st.vols{h(1)}.ax{1}.ax;
0485     st.registry = struct('hReg',hreg,'hMe', tmp);
0486     spm_XYZreg('Add2Reg',st.registry.hReg,st.registry.hMe, 'mars_orthviews');
0487 else,
0488     warning('Nothing to register with');
0489 end;
0490 st.centre = spm_XYZreg('GetCoords',st.registry.hReg);
0491 st.centre = st.centre(:);
0492 return;
0493 %_______________________________________________________________________
0494 %_______________________________________________________________________
0495 function xhairs(arg1),
0496 global st
0497 st.xhairs = 0;
0498 opt = 'on';
0499 if ~strcmp(arg1,'on'),
0500     opt = 'off';
0501 else,
0502     st.xhairs = 1;
0503 end;
0504 for i=valid_handles(1:24),
0505     for j=1:3,
0506         set(st.vols{i}.ax{j}.lx,'Visible',opt); 
0507         set(st.vols{i}.ax{j}.ly,'Visible',opt);  
0508     end; 
0509 end;
0510 return;
0511 %_______________________________________________________________________
0512 %_______________________________________________________________________
0513 function H = pos(arg1)
0514 global st
0515 H = [];
0516 for arg1=valid_handles(arg1),
0517     is = inv(st.vols{arg1}.premul*st.vols{arg1}.mat);
0518     H = is(1:3,1:3)*st.centre(:) + is(1:3,4);
0519 end;
0520 return;
0521 %_______________________________________________________________________
0522 %_______________________________________________________________________
0523 function my_reset
0524 global st
0525 if ~isempty(st) & isfield(st,'registry') & ishandle(st.registry.hMe),
0526     delete(st.registry.hMe); st = rmfield(st,'registry');
0527 end;
0528 my_delete(1:24);
0529 reset_st;
0530 return;
0531 %_______________________________________________________________________
0532 %_______________________________________________________________________
0533 function my_delete(arg1)
0534 global st
0535 for i=valid_handles(arg1),
0536     kids = get(st.fig,'Children');
0537     for j=1:3,
0538         if any(kids == st.vols{i}.ax{j}.ax),
0539             set(get(st.vols{i}.ax{j}.ax,'Children'),'DeleteFcn','');
0540             delete(st.vols{i}.ax{j}.ax);
0541         end;
0542     end;
0543     st.vols{i} = [];
0544 end;
0545 return;
0546 %_______________________________________________________________________
0547 %_______________________________________________________________________
0548 function resolution(arg1)
0549 global st
0550 res      = arg1/mean(svd(st.Space(1:3,1:3)));
0551 Mat      = diag([res res res 1]);
0552 st.Space = st.Space*Mat;
0553 st.bb    = st.bb/res;
0554 return;
0555 %_______________________________________________________________________
0556 %_______________________________________________________________________
0557 function move(handle,pos)
0558 global st
0559 for handle = valid_handles(handle),
0560     st.vols{handle}.area = pos;
0561 end;
0562 bbox;
0563 % redraw(valid_handles(handle));
0564 return;
0565 %_______________________________________________________________________
0566 %_______________________________________________________________________
0567 function bb = maxbb
0568 global st
0569 mn = [Inf Inf Inf];
0570 mx = -mn;
0571 for i=valid_handles(1:24),
0572     bb = [[1 1 1];st.vols{i}.dim(1:3)];
0573     c = [    bb(1,1) bb(1,2) bb(1,3) 1
0574         bb(1,1) bb(1,2) bb(2,3) 1
0575         bb(1,1) bb(2,2) bb(1,3) 1
0576         bb(1,1) bb(2,2) bb(2,3) 1
0577         bb(2,1) bb(1,2) bb(1,3) 1
0578         bb(2,1) bb(1,2) bb(2,3) 1
0579         bb(2,1) bb(2,2) bb(1,3) 1
0580         bb(2,1) bb(2,2) bb(2,3) 1]';
0581     tc = st.Space\(st.vols{i}.premul*st.vols{i}.mat)*c;
0582     tc = tc(1:3,:)';
0583     mx = max([tc ; mx]);
0584     mn = min([tc ; mn]);
0585 end;
0586 bb = [mn ; mx];
0587 return;
0588 %_______________________________________________________________________
0589 %_______________________________________________________________________
0590 function space(arg1)
0591 global st
0592 if ~isempty(st.vols{arg1})
0593     num = arg1;
0594     Mat = st.vols{num}.premul(1:3,1:3)*st.vols{num}.mat(1:3,1:3);
0595     Mat = diag([sqrt(sum(Mat.^2)) 1]);
0596     Space = (st.vols{num}.mat)/Mat;
0597     bb = [1 1 1;st.vols{num}.dim(1:3)];
0598     bb = [bb [1;1]];
0599     bb=bb*Mat';
0600     bb=bb(:,1:3);
0601     st.Space  = Space;
0602     st.bb = bb;
0603 end;
0604 return;
0605 %_______________________________________________________________________
0606 %_______________________________________________________________________
0607 function H = specify_image(arg1, arg2)
0608 global st
0609 H=[];
0610 ok = 1;
0611 eval('V = spm_vol(arg1);','ok=0;');
0612 if ok == 0,
0613     fprintf('Can not use image "%s"\n', arg1);
0614     return;
0615 end;
0616 
0617 ii = 1;
0618 while ~isempty(st.vols{ii}), ii = ii + 1; end;
0619 
0620 DeleteFcn = ['mars_orthviews(''Delete'',' num2str(ii) ');'];
0621 V.ax = cell(3,1);
0622 for i=1:3,
0623     ax = axes('Visible','off','DrawMode','fast','Parent',st.fig,'DeleteFcn',DeleteFcn,...
0624         'YDir','normal');
0625     d  = image(0,'Tag','Transverse','Parent',ax,...
0626         'DeleteFcn',DeleteFcn);
0627     set(ax,'Ydir','normal');
0628     lx = line(0,0,'Parent',ax,'DeleteFcn',DeleteFcn);
0629     ly = line(0,0,'Parent',ax,'DeleteFcn',DeleteFcn);
0630     if ~st.xhairs,
0631         set(lx,'Visible','off');
0632         set(ly,'Visible','off');
0633     end;
0634     V.ax{i} = struct('ax',ax,'d',d,'lx',lx,'ly',ly);
0635 end;
0636 V.premul    = eye(4);
0637 V.window    = 'auto';
0638 st.vols{ii} = V;
0639 
0640 H = ii;
0641 return;
0642 %_______________________________________________________________________
0643 %_______________________________________________________________________
0644 function bbox
0645 global st
0646 Dims = diff(st.bb)'+1;
0647 
0648 TD = Dims([1 2])';
0649 CD = Dims([1 3])';
0650 if st.mode == 0, SD = Dims([3 2])'; else, SD = Dims([2 3])'; end;
0651 
0652 un    = get(st.fig,'Units');set(st.fig,'Units','Pixels');sz=get(st.fig,'Position');set(st.fig,'Units',un);
0653 sz    = sz(3:4);
0654 sz(2) = sz(2)-40;
0655 
0656 for i=valid_handles(1:24),
0657     area = st.vols{i}.area(:);
0658     area = [area(1)*sz(1) area(2)*sz(2) area(3)*sz(1) area(4)*sz(2)];
0659     if st.mode == 0,
0660         sx   = area(3)/(Dims(1)+Dims(3))/1.02;
0661     else,
0662         sx   = area(3)/(Dims(1)+Dims(2))/1.02;
0663     end;
0664     sy   = area(4)/(Dims(2)+Dims(3))/1.02;
0665     s    = min([sx sy]);
0666 
0667     offy = (area(4)-(Dims(2)+Dims(3))*1.02*s)/2 + area(2);
0668     sky = s*(Dims(2)+Dims(3))*0.02;
0669     if st.mode == 0,
0670         offx = (area(3)-(Dims(1)+Dims(3))*1.02*s)/2 + area(1);
0671         skx = s*(Dims(1)+Dims(3))*0.02;
0672     else,
0673         offx = (area(3)-(Dims(1)+Dims(2))*1.02*s)/2 + area(1);
0674         skx = s*(Dims(1)+Dims(2))*0.02;
0675     end;
0676 
0677     DeleteFcn = ['mars_orthviews(''Delete'',' num2str(i) ');'];
0678 
0679     % Transverse
0680     set(st.vols{i}.ax{1}.ax,'Units','pixels', ...
0681         'Position',[offx offy s*Dims(1) s*Dims(2)],...
0682         'Units','normalized','Xlim',[0 TD(1)]+0.5,'Ylim',[0 TD(2)]+0.5,...
0683         'Visible','on','XTick',[],'YTick',[]);
0684 
0685     % Coronal
0686     set(st.vols{i}.ax{2}.ax,'Units','Pixels',...
0687         'Position',[offx offy+s*Dims(2)+sky s*Dims(1) s*Dims(3)],...
0688         'Units','normalized','Xlim',[0 CD(1)]+0.5,'Ylim',[0 CD(2)]+0.5,...
0689         'Visible','on','XTick',[],'YTick',[]);
0690 
0691     % Sagittal
0692     if st.mode == 0,
0693         set(st.vols{i}.ax{3}.ax,'Units','Pixels', 'Box','on',...
0694             'Position',[offx+s*Dims(1)+skx offy s*Dims(3) s*Dims(2)],...
0695             'Units','normalized','Xlim',[0 SD(1)]+0.5,'Ylim',[0 SD(2)]+0.5,...
0696             'Visible','on','XTick',[],'YTick',[]);
0697     else,
0698         set(st.vols{i}.ax{3}.ax,'Units','Pixels', 'Box','on',...
0699             'Position',[offx+s*Dims(1)+skx offy+s*Dims(2)+sky s*Dims(2) s*Dims(3)],...
0700             'Units','normalized','Xlim',[0 SD(1)]+0.5,'Ylim',[0 SD(2)]+0.5,...
0701             'Visible','on','XTick',[],'YTick',[]);
0702     end;
0703 end;
0704 return;
0705 %_______________________________________________________________________
0706 %_______________________________________________________________________
0707 function redraw_all
0708 global st
0709 redraw(1:24);
0710 return;
0711 %_______________________________________________________________________
0712 function mx = maxval(vol)
0713 if isstruct(vol) & isfield(vol, 'vol'), vol = vol.vol;end
0714 if isstruct(vol),
0715     mx = -Inf;
0716     for i=1:vol.dim(3),
0717         tmp = spm_slice_vol(vol,spm_matrix([0 0 i]),vol.dim(1:2),0);
0718         imx = max(tmp(find(isfinite(tmp))));
0719         if ~isempty(imx),mx = max(mx,imx);end
0720     end;
0721 else,
0722     mx = max(vol(find(isfinite(vol))));
0723 end;
0724 %_______________________________________________________________________
0725 function mn = minval(vol)
0726 if isstruct(vol) & isfield(vol, 'vol'), vol = vol.vol;end
0727 if isstruct(vol),
0728         mn = Inf;
0729         for i=1:vol.dim(3),
0730                 tmp = spm_slice_vol(vol,spm_matrix([0 0 i]),vol.dim(1:2),0);
0731         imn = min(tmp(find(isfinite(tmp))));
0732         if ~isempty(imn),mn = min(mn,imn);end
0733         end;
0734 else,
0735         mn = min(vol(find(isfinite(vol))));
0736 end;
0737 
0738 %_______________________________________________________________________
0739 %_______________________________________________________________________
0740 function redraw(arg1)
0741 global st
0742 bb   = st.bb;
0743 Dims = diff(bb)'+1;
0744 is   = inv(st.Space);
0745 cent = is(1:3,1:3)*st.centre(:) + is(1:3,4);
0746 
0747 for i = valid_handles(arg1),
0748     M = st.vols{i}.premul*st.vols{i}.mat;
0749     TM0 = [    1 0 0 -bb(1,1)+1
0750         0 1 0 -bb(1,2)+1
0751         0 0 1 -cent(3)
0752         0 0 0 1];
0753     TM = inv(TM0*(st.Space\M));
0754     TD = Dims([1 2]);
0755 
0756     CM0 = [    1 0 0 -bb(1,1)+1
0757         0 0 1 -bb(1,3)+1
0758         0 1 0 -cent(2)
0759         0 0 0 1];
0760     CM = inv(CM0*(st.Space\M));
0761     CD = Dims([1 3]);
0762 
0763     if st.mode ==0,
0764         SM0 = [    0 0 1 -bb(1,3)+1
0765             0 1 0 -bb(1,2)+1
0766             1 0 0 -cent(1)
0767             0 0 0 1];
0768         SM = inv(SM0*(st.Space\M)); SD = Dims([3 2]);
0769     else,
0770         SM0 = [    0  1 0 -bb(1,2)+1
0771             0  0 1 -bb(1,3)+1
0772             1  0 0 -cent(1)
0773             0  0 0 1];
0774         SM0 = [    0 -1 0 +bb(2,2)+1
0775             0  0 1 -bb(1,3)+1
0776             1  0 0 -cent(1)
0777             0  0 0 1];
0778         SM = inv(SM0*(st.Space\M));
0779         SD = Dims([2 3]);
0780     end;
0781 
0782     ok=1;
0783     eval('imgt  = (spm_slice_vol(st.vols{i},TM,TD,st.hld))'';','ok=0;');
0784     eval('imgc  = (spm_slice_vol(st.vols{i},CM,CD,st.hld))'';','ok=0;');
0785     eval('imgs  = (spm_slice_vol(st.vols{i},SM,SD,st.hld))'';','ok=0;');
0786     if (ok==0), fprintf('Image "%s" can not be resampled\n', st.vols{i}.fname);
0787     else,
0788         if strcmp(st.vols{i}.window,'auto'),
0789             mx = -Inf; mn = Inf;
0790             if ~isempty(imgt),
0791                 mx = max([mx max(max(imgt))]);
0792                 mn = min([mn min(min(imgt))]);
0793             end;
0794             if ~isempty(imgc),
0795                 mx = max([mx max(max(imgc))]);
0796                 mn = min([mn min(min(imgc))]);
0797             end;
0798             if ~isempty(imgs),
0799                 mx = max([mx max(max(imgs))]);
0800                 mn = min([mn min(min(imgs))]);
0801             end;
0802             if mx==mn, mx=mn+eps; end;
0803         else,
0804             mx = st.vols{i}.window(2);
0805             mn = st.vols{i}.window(1);
0806             r=min([mn mx]);imgt = max(imgt,r); r=max([mn mx]);imgt = min(imgt,r);
0807             r=min([mn mx]);imgc = max(imgc,r); r=max([mn mx]);imgc = min(imgc,r);
0808             r=min([mn mx]);imgs = max(imgs,r); r=max([mn mx]);imgs = min(imgs,r);
0809         end;
0810 
0811         if isfield(st.vols{i},'blobs'),
0812             if ~isfield(st.vols{i}.blobs{1},'colour'),
0813                 % Add blobs for display using the split colourmap
0814                 scal = 64/(mx-mn);
0815                 dcoff = -mn*scal;
0816                 imgt = imgt*scal+dcoff;
0817                 imgc = imgc*scal+dcoff;
0818                 imgs = imgs*scal+dcoff;
0819 
0820                 vol = st.vols{i}.blobs{1}.vol;
0821                 mat = st.vols{i}.premul*st.vols{i}.blobs{1}.mat;
0822                 if isfield(st.vols{i}.blobs{1},'max'),
0823                     mx = st.vols{i}.blobs{1}.max;
0824                 else,
0825                     mx = max([eps maxval(st.vols{i}.blobs{1}.vol)]);
0826                     st.vols{i}.blobs{1}.max = mx;
0827                 end;
0828                 if isfield(st.vols{i}.blobs{1},'min'),
0829                     mn = st.vols{i}.blobs{1}.min;
0830                 else,
0831                     mn = min([0 minval(st.vols{i}.blobs{1}.vol)]);
0832                     st.vols{i}.blobs{1}.min = mn;
0833                 end;
0834 
0835                 vol  = st.vols{i}.blobs{1}.vol;
0836                 M    = st.vols{i}.premul*st.vols{i}.blobs{1}.mat;
0837                 tmpt = spm_slice_vol(vol,inv(TM0*(st.Space\M)),TD,[0 NaN])';
0838                 tmpc = spm_slice_vol(vol,inv(CM0*(st.Space\M)),CD,[0 NaN])';
0839                 tmps = spm_slice_vol(vol,inv(SM0*(st.Space\M)),SD,[0 NaN])';
0840 
0841                 sc   = 64/(mx-mn);
0842                 off  = 65.51-mn*sc;
0843                 msk  = find(isfinite(tmpt)); imgt(msk) = off+tmpt(msk)*sc;
0844                 msk  = find(isfinite(tmpc)); imgc(msk) = off+tmpc(msk)*sc;
0845                 msk  = find(isfinite(tmps)); imgs(msk) = off+tmps(msk)*sc;
0846 
0847                 cmap = get(st.fig,'Colormap');
0848                 if size(cmap,1)~=128
0849                     figure(st.fig)
0850                     spm_figure('Colormap','gray-hot')
0851                 end;
0852             elseif isstruct(st.vols{i}.blobs{1}.colour),
0853                 % Add blobs for display using a defined
0854                                 % colourmap
0855 
0856                 % colourmaps
0857                 gryc = [0:63]'*ones(1,3)/63;
0858                 actc = ...
0859                     st.vols{1}.blobs{1}.colour.cmap;
0860                 actp = ...
0861                     st.vols{1}.blobs{1}.colour.prop;
0862                 
0863                 % scale grayscale image, not finite -> black
0864                 imgt = scaletocmap(imgt,mn,mx,gryc,65);
0865                 imgc = scaletocmap(imgc,mn,mx,gryc,65);
0866                 imgs = scaletocmap(imgs,mn,mx,gryc,65);
0867                 gryc = [gryc; 0 0 0];
0868                 
0869                 % get max for blob image
0870                 vol = st.vols{i}.blobs{1}.vol;
0871                 mat = st.vols{i}.premul*st.vols{i}.blobs{1}.mat;
0872                 if isfield(st.vols{i}.blobs{1},'max'),
0873                     cmx = st.vols{i}.blobs{1}.max;
0874                 else,
0875                     cmx = max([eps maxval(st.vols{i}.blobs{1}.vol)]);
0876                 end;
0877 
0878                 % get blob data
0879                 vol  = st.vols{i}.blobs{1}.vol;
0880                 M    = st.vols{i}.premul*st.vols{i}.blobs{1}.mat;
0881                 tmpt = spm_slice_vol(vol,inv(TM0*(st.Space\M)),TD,[0 NaN])';
0882                 tmpc = spm_slice_vol(vol,inv(CM0*(st.Space\M)),CD,[0 NaN])';
0883                 tmps = spm_slice_vol(vol,inv(SM0*(st.Space\M)),SD,[0 NaN])';
0884                 
0885                 % actimg scaled round 0, black NaNs
0886                                 topc = size(actc,1)+1;
0887                 tmpt = scaletocmap(tmpt,-cmx,cmx,actc,topc);
0888                 tmpc = scaletocmap(tmpc,-cmx,cmx,actc,topc);
0889                 tmps = scaletocmap(tmps,-cmx,cmx,actc,topc);
0890                 actc = [actc; 0 0 0];
0891                 
0892                 % combine gray and blob data to
0893                                 % truecolour
0894                 imgt = reshape(actc(tmpt(:),:)*actp+ ...
0895                            gryc(imgt(:),:)*(1-actp), ...
0896                            [size(imgt) 3]);
0897                 imgc = reshape(actc(tmpc(:),:)*actp+ ...
0898                            gryc(imgc(:),:)*(1-actp), ...
0899                            [size(imgc) 3]);
0900                 imgs = reshape(actc(tmps(:),:)*actp+ ...
0901                            gryc(imgs(:),:)*(1-actp), ...
0902                            [size(imgs) 3]);
0903                 
0904                 
0905             else,
0906                 % Add full colour blobs - several sets at once
0907                 scal = 1/(mx-mn);
0908                 dcoff = -mn*scal;
0909                 imgt = repmat(imgt*scal+dcoff,[1,1,3]);
0910                 imgc = repmat(imgc*scal+dcoff,[1,1,3]);
0911                 imgs = repmat(imgs*scal+dcoff,[1,1,3]);
0912 
0913                 for j=1:length(st.vols{i}.blobs),
0914                     vol = st.vols{i}.blobs{j}.vol;
0915                     mat = st.vols{i}.premul*st.vols{i}.blobs{j}.mat;
0916                     if isfield(st.vols{i}.blobs{j},'colour'),
0917                         colour = st.vols{i}.blobs{j}.colour;
0918                     else,
0919                         colour = [1 0 0];
0920                     end;
0921                     if isfield(st.vols{i}.blobs{j},'max'),
0922                         mx = st.vols{i}.blobs{j}.max;
0923                     else,
0924                         mx = max([eps max(st.vols{i}.blobs{j}.vol(:))]);
0925                         st.vols{i}.blobs{j}.max = mx;
0926                     end;
0927                     if isfield(st.vols{i}.blobs{j},'min'),
0928                         mn = st.vols{i}.blobs{j}.min;
0929                     else,
0930                         mn = min([0 min(st.vols{i}.blobs{j}.vol(:))]);
0931                         st.vols{i}.blobs{j}.min = mn;
0932                     end;
0933 
0934                     vol  = st.vols{i}.blobs{j}.vol;
0935                     M    = st.vols{i}.premul*st.vols{i}.blobs{j}.mat;
0936                     tmpt = spm_slice_vol(vol,inv(TM0*(st.Space\M)),TD,[0 NaN])'/(mx-mn)+mn;
0937                     tmpc = spm_slice_vol(vol,inv(CM0*(st.Space\M)),CD,[0 NaN])'/(mx-mn)+mn;
0938                     tmps = spm_slice_vol(vol,inv(SM0*(st.Space\M)),SD,[0 NaN])'/(mx-mn)+mn;
0939                     tmpt(find(~isfinite(tmpt))) = 0;
0940                     tmpc(find(~isfinite(tmpc))) = 0;
0941                     tmps(find(~isfinite(tmps))) = 0;
0942 
0943                     tmp  = cat(3,tmpt*colour(1),tmpt*colour(2),tmpt*colour(3));
0944                     imgt = (repmat(1-tmpt,[1 1 3]).*imgt+tmp);
0945                     tmp = find(imgt<0); imgt(tmp)=0; tmp = find(imgt>1); imgt(tmp)=1;
0946 
0947                     tmp  = cat(3,tmpc*colour(1),tmpc*colour(2),tmpc*colour(3));
0948                     imgc = (repmat(1-tmpc,[1 1 3]).*imgc+tmp);
0949                     tmp = find(imgc<0); imgc(tmp)=0; tmp = find(imgc>1); imgc(tmp)=1;
0950 
0951                     tmp  = cat(3,tmps*colour(1),tmps*colour(2),tmps*colour(3));
0952                     imgs = (repmat(1-tmps,[1 1 3]).*imgs+tmp);
0953                     tmp = find(imgs<0); imgs(tmp)=0; tmp = find(imgs>1); imgs(tmp)=1;
0954                 end;
0955             end;
0956         else,
0957             scal = 64/(mx-mn);
0958             dcoff = -mn*scal;
0959             imgt = imgt*scal+dcoff;
0960             imgc = imgc*scal+dcoff;
0961             imgs = imgs*scal+dcoff;
0962         end;
0963 
0964         callback = 'mars_orthviews(''Reposition'');';
0965 
0966         set(st.vols{i}.ax{1}.d,'ButtonDownFcn',callback, 'Cdata',imgt);
0967         set(st.vols{i}.ax{1}.lx,'ButtonDownFcn',callback,...
0968             'Xdata',[0 TD(1)]+0.5,'Ydata',[1 1]*(cent(2)-bb(1,2)+1));
0969         set(st.vols{i}.ax{1}.ly,'ButtonDownFcn',callback,...
0970             'Ydata',[0 TD(2)]+0.5,'Xdata',[1 1]*(cent(1)-bb(1,1)+1));
0971 
0972         set(st.vols{i}.ax{2}.d,'ButtonDownFcn',callback, 'Cdata',imgc);
0973         set(st.vols{i}.ax{2}.lx,'ButtonDownFcn',callback,...
0974             'Xdata',[0 CD(1)]+0.5,'Ydata',[1 1]*(cent(3)-bb(1,3)+1));
0975         set(st.vols{i}.ax{2}.ly,'ButtonDownFcn',callback,...
0976             'Ydata',[0 CD(2)]+0.5,'Xdata',[1 1]*(cent(1)-bb(1,1)+1));
0977 
0978         set(st.vols{i}.ax{3}.d,'ButtonDownFcn',callback,'Cdata',imgs);
0979         if st.mode ==0,
0980             set(st.vols{i}.ax{3}.lx,'ButtonDownFcn',callback,...
0981                 'Xdata',[0 SD(1)]+0.5,'Ydata',[1 1]*(cent(2)-bb(1,2)+1));
0982             set(st.vols{i}.ax{3}.ly,'ButtonDownFcn',callback,...
0983                 'Ydata',[0 SD(2)]+0.5,'Xdata',[1 1]*(cent(3)-bb(1,3)+1));
0984         else,
0985             set(st.vols{i}.ax{3}.lx,'ButtonDownFcn',callback,...
0986                 'Xdata',[0 SD(1)]+0.5,'Ydata',[1 1]*(cent(3)-bb(1,3)+1));
0987             set(st.vols{i}.ax{3}.ly,'ButtonDownFcn',callback,...
0988                 'Ydata',[0 SD(2)]+0.5,'Xdata',[1 1]*(bb(2,2)+1-cent(2)));
0989         end;
0990     end;
0991 end;
0992 drawnow;
0993 return;
0994 %_______________________________________________________________________
0995 %_______________________________________________________________________
0996 function centre = findcent
0997 global st
0998 obj    = get(st.fig,'CurrentObject');
0999 centre = [];
1000 cent   = [];
1001 cp     = [];
1002 for i=valid_handles(1:24),
1003     for j=1:3,
1004         if ~isempty(obj),
1005             if any([st.vols{i}.ax{j}.d  ...
1006                 st.vols{i}.ax{j}.lx ...
1007                 st.vols{i}.ax{j}.ly]== obj)
1008                 cp = get(get(obj,'Parent'),'CurrentPoint');
1009             elseif (st.vols{i}.ax{j}.ax == obj),
1010                 cp = get(obj,'CurrentPoint');
1011             end;
1012         end;
1013         if ~isempty(cp),
1014             cp   = cp(1,1:2);
1015             is   = inv(st.Space);
1016             cent = is(1:3,1:3)*st.centre(:) + is(1:3,4);
1017             switch j,
1018                 case 1,
1019                 cent([1 2])=[cp(1)+st.bb(1,1)-1 cp(2)+st.bb(1,2)-1];
1020                 case 2,
1021                 cent([1 3])=[cp(1)+st.bb(1,1)-1 cp(2)+st.bb(1,3)-1];
1022                 case 3,
1023                 if st.mode ==0,
1024                     cent([3 2])=[cp(1)+st.bb(1,3)-1 cp(2)+st.bb(1,2)-1];
1025                 else,
1026                     cent([2 3])=[st.bb(2,2)+1-cp(1) cp(2)+st.bb(1,3)-1];
1027                 end;
1028             end;
1029             break;
1030         end;
1031     end;
1032     if ~isempty(cent), break; end;
1033 end;
1034 if ~isempty(cent), centre = st.Space(1:3,1:3)*cent(:) + st.Space(1:3,4); end;
1035 return;
1036 %_______________________________________________________________________
1037 %_______________________________________________________________________
1038 function handles = valid_handles(handles)
1039 global st;
1040 handles = handles(:)';
1041 handles = handles(find(handles<=24 & handles>=1 & ~rem(handles,1)));
1042 for h=handles,
1043     if isempty(st.vols{h}), handles(find(handles==h))=[]; end;
1044 end;
1045 return;
1046 %_______________________________________________________________________
1047 %_______________________________________________________________________
1048 function reset_st
1049 global st
1050 fig     = spm_figure('FindWin','Graphics');
1051 bb      = [ [-78 78]' [-112 76]' [-50 85]' ];
1052 st      = struct('n', 0, 'vols',[], 'bb',bb,'Space',eye(4),'centre',[0 0 0],'callback',';','xhairs',1,'hld',1,'fig',fig,'mode',1);
1053 st.vols = cell(24,1);
1054 return;
1055 %_______________________________________________________________________
1056 %_______________________________________________________________________
1057 function img = scaletocmap(inpimg,mn,mx,cmap,miscol)
1058 if nargin < 5, miscol=1;end
1059 cml = size(cmap,1);
1060 scf = (cml-1)/(mx-mn);
1061 img = round((inpimg-mn)*scf)+1;
1062 img(find(img<1))=1; 
1063 img(find(img>cml))=cml;
1064 img(~isfinite(img)) = miscol;
1065 %_______________________________________________________________________
1066 %_______________________________________________________________________
1067 function cmap = getcmap(acmapname)
1068 % get colormap of name acmapname
1069 if ~isempty(acmapname)
1070   cmap = evalin('base',acmapname,'[]');
1071   if isempty(cmap) % not a matrix, is .mat file?
1072     [p f e] = fileparts(acmapname);
1073     acmat = fullfile(p, [f '.mat']);
1074     if exist(acmat, 'file')
1075       s = struct2cell(load(acmat));
1076       cmap = s{1};
1077     end
1078   end
1079 end
1080 if size(cmap, 2)~=3
1081   warning('Colormap was not an N by 3 matrix')
1082   cmap = [];
1083 end
1084 return

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019