Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


GetAfniSlice.m

Go to the documentation of this file.
00001 function [err, slc, slcDisp] = GetAfniSlice (Brik, BrikInfo, Opt)
00002 %
00003 %   [err, slc, slcDisp] = GetAfniSlice (Brik, BrikInfo, Opt)
00004 %
00005 %Purpose:
00006 %   Display a slice as it appears in the AFNI window
00007 %   
00008 %   
00009 %Input Parameters:
00010 %   Brik: is a vector or a matrix containing the brik values
00011 %   BrikInfo is a structure containing Header info
00012 %      (both are output by BrikLoad function)
00013 %   Opt is a an options structure with the following fields
00014 %    .plane is the slicing plane. Choose from 'Ax', 'Sa' and 'Co' for axial, sagittal and coronal
00015 %    .iSlc is an Nx1 vector with slice indices to show (a la AFNI, first slice is indexed 0)
00016 %    .index is the sub-brick index, default is 0
00017 %   
00018 %Output Parameters:
00019 %   err : 0 No Problem
00020 %       : 1 Mucho Problems
00021 %   slc is a structure containing the slices
00022 %    .M   [N x M x k] , k being the number of slices requested in Opt.i*
00023 %    .orientax a 2x2 character matrix. The 1st and 2nd rows indicates the orientation 
00024 %          of the voxels in the 1st  and 2nd dimension of .M, respectively.
00025 %          for example: if orientax is [RL; AP] or 
00026 %          RL
00027 %          AP
00028 %          This means that the pixels in slc.M go from Right to Left along the 1st dimension of the 
00029 %          matrix (ie along columns, top to bottom). Pixels go from Anterior to Posterior along the second
00030 %          dimension of the matrix (ie along rows, left to right).
00031 %  
00032 %   slcDisp is a structure similar to slc and containing the slices oriented as they would be displayed in AFNI's window   
00033 %   
00034 %      
00035 %Key Terms:
00036 %   
00037 %More Info :
00038 %   Test_GetAfniSliceTriplet
00039 %   GetAfniSlice
00040 %        AFNI_SliceDispManip
00041 %       GetAfniSliceTriplet
00042 %
00043 %
00044 %     Author : Ziad Saad
00045 %     Date : Tue Aug 22 18:36:04 PDT 2000
00046 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00047 %    last modified: Mon Aug 27 13:29:42 PDT 2001
00048 
00049 
00050 %Define the function name for easy referencing
00051 FuncName = 'GetAfniSlice';
00052 
00053 %Debug Flag
00054 DBG = 1;
00055 
00056 %turn Brick into a matrix if it isn't already
00057 if (ndims(Brik) < 3),
00058         Brik = reshape(Brik, BrikInfo.DATASET_DIMENSIONS(1), BrikInfo.DATASET_DIMENSIONS(2),...
00059                                                 BrikInfo.DATASET_DIMENSIONS(3), BrikInfo.DATASET_RANK(2));
00060 end
00061 
00062 %initailize return variables
00063 err = 1;
00064         switch Opt.plane,
00065                 case 'Ax',
00066                         iplane = 1;
00067                 case 'Sa',
00068                         iplane = 2;
00069                 case 'Co',
00070                         iplane = 3;
00071         end
00072 
00073 if (~isfield(Opt,'index') |isempty(Opt.index)), Opt.index = 0; end
00074 
00075 indx = Opt.index+1;
00076 
00077 DispManip = AFNI_SliceDispManip (BrikInfo);             
00078 
00079 if (DispManip(iplane).zflip), 
00080                         %added -1 on Mon Aug 27 13:29:42 PDT 2001
00081         Opt.iSlc = BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).SliceDim) - Opt.iSlc -1;
00082 end
00083 
00084         nz = length(Opt.iSlc);
00085         if (nz),
00086                 %allocate enough space
00087                         slc.M = zeros(BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(1)), BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(2)), nz); 
00088                         bufslc = zeros(BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(1)), BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(2)));
00089                         if (DispManip(iplane).orpermute),
00090                                 slcDisp.M = zeros(BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(2)), BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(1)), nz);
00091                         else
00092                                 slcDisp.M = zeros(BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(1)), BrikInfo.DATASET_DIMENSIONS(DispManip(iplane).d(2)), nz);
00093                         end
00094                         
00095                 %first grab the slices
00096                 switch DispManip(iplane).SliceDim,
00097                         case 1,                                 
00098                                 for (j=1:1:nz),
00099                                         slc.M(:,:,j) = Brik(Opt.iSlc(j)+1, :, :, indx);
00100                                 end
00101                         case 2
00102                                 for (j=1:1:nz),
00103                                         slc.M(:,:,j) = Brik(:, Opt.iSlc(j)+1, :, indx);
00104                                 end
00105                         case 3
00106                                 for (j=1:1:nz),
00107                                         slc.M(:,:,j) = Brik(:, :, Opt.iSlc(j)+1, indx);
00108                                 end
00109                 end %switch DispManip(iplane).SliceDim,
00110                 
00111                 %now manipulate them to have them display properly 
00112                 for (j=1:1:nz),
00113                         bufslc = slc.M(:,:,j); %this is inefficient, might want to dump this step
00114                         if (DispManip(iplane).orpermute), bufslc = permute(bufslc,[2 1]);       end
00115                         if (DispManip(iplane).udflip), bufslc = flipud(bufslc); end
00116                         if (DispManip(iplane).lrflip), bufslc = fliplr(bufslc); end
00117                         slcDisp.M(:,:,j) = bufslc;
00118                 end
00119         end %if (nz)
00120 
00121 
00122 err = 0;
00123 return;
00124 
 

Powered by Plone

This site conforms to the following standards: