Home > fe > feGet.m

feGet

PURPOSE ^

Get function for fascicle evaluation structure

SYNOPSIS ^

function val = feGet(fe,param,varargin)

DESCRIPTION ^

 Get function for fascicle evaluation structure

   val = feGet(fe,param,varargin)


 INPUTS: 
  Coords    - Nx3 set of coordinates in image space
  voxelIndices - Vector of 1's and 0's, there is a one for each
              location the the connectome coordinates for which there is
              a match in the coords


 Copyright (2013-2014), Franco Pestilli & Brian Wandell, 
  Stanford University, pestillifranco@gmail.com.


---------- List of arguments ----
 Name of the current fe structure.
 name = feGet(fe,'name')
----------
 The type of objes (always, fascicle evaluation)
 type = feGet(fe,'type')
----------
 Structure of parameters and results from LIFE analysis
 life = feGet(fe,'life')
----------
 Return the connectome (fiber group) in image coordinates.
 fg = feGEt(fe,'fg img')
----------
 return the connectome in acpc coordinates.
 fg  = feGet(fg,'fg acpc')
----------
 Return the VOI comprised by the full connectome.
 roi = feGet(fe,'roi')
----------
 Transforms between coords for fg, roi, and dwi data
 xform = feGet(fe,'xform')
----------
 Load the diffusion weighted data.
 dwi = feGet(fe,'dwi')
----------
 Return the path to the diffusion weighted data file.
 dwiFile = feGet(fe,'dwifile')   
----------
 Load the repeated-measure diffusion weighted data.
 dwi = feGet(fe,'dwirepeat') 
----------
 Load the repeated measure of the diffusion weighted data.
 dwiFile = feGet(fe,'dwirepeatfile')
----------
 Directory where the LiFe structes are saved by defualt.
 sdir = feGet(fe,'savedir');
----------
 Diffusion directions.
 val = feGet(fe,'bvecs');
----------
 Indices to the diffusion directions in the DWi 4th Dimension.
 val = feGet(fe,'bvecs indices');
----------
 Number of B0's
 val = feGet(fe,'n bvals');
----------
 B0 Values.
 bval = feGet(fe,'bvals')
----------
 Returns a nVoxels X nBvecs array of measured diffusion signal
 val = feGet(fe,'dsiinvox');
 val = feGet(fe,'dsiinvox',voxelsIndices);
 val = feGet(fe,'dsiinvox',coords);
----------
 Returns a nVoxels X nBvecs array of demeaned diffusion signal
 val =feGet(fe,'dsiinvoxdemeaned');
 val =feGet(fe,'dsiinvoxdemeaned',voxelsIndices);
 val =feGet(fe,'dsiinvoxdemeaned',coords);
----------
 Get the diffusion signal at 0 diffusion weighting (B0) for this voxel
 val = feGet(fe,'b0signalvoxel');
 val = feGet(fe,'b0signalvoxel',voxelIndex);
 val = feGet(fe,'b0signalvoxel',coords);
----------
 Return a subset of fibers from the conenctome.
 fg = feGet(fe,'fiberssubset',fiberList);
----------
 Return the coordinates of the VOI comprised in the connectome.
 Always in image space.
 coords = feGet(fe,'roi coords')
----------
 Number of voxels in the connectome/VOI.
 nVoxels = feGet(fe,'n voxels')
----------
 Indexes of actually used voxels.
 These can be different than the number of voxels in the VOI in case some
 voxels have no fibers in them.

 TO BE DEPRECATED.
 indxUsedVx = feGet(fe,'index of used voxels')
----------
 Number of actually used voxels.
 This can be less than the number of voxels in the VOI in case some
 voxels have no fibers in them.

 TO BE DEPRECATED.
 nUsedVx = feGet(fe,'index of used voxels')
----------
 Returns the first index to a voxel in the dSig vector.
 The dSig vector is 1:nBvecs*nVoxels.
 val = feGet(fe,'start rows')
----------
 Return the rows corresponding to a set of voxels.
 rows = feGet(fe,'voxel rows',idxVoxel)
----------
 Return the model (M matrix), or a subset of it.
 Mfiber = feGet(fe,'M fiber');
 Mfiber = feGet(fe,'model',voxelsIndices);
 Mfiber = feGet(fe,'model',coords);
----------
 Return a subset of measurements from the fiber portion of M matrix
 The rows of M are specified.  Remember that the rows refer to a
 combination of voxel and measurement direction and potentially in the
 future a b-value.  Hence, the rows are not specific to a voxel.
 Mfiber = feGet(fe,'mfiber subset',rowsToKeep);
----------
 Pairing of fibers and nodes in each voxel.
 v2fnp = feGet(fe,'v2fnp');
----------
 Tensors computed for each node and fiber in a set of voxels.
 t = feGet(fe,'tensors')
 t = feGet(fe,'tensors',voxelsIndices);
 t = feGet(fe,'tensors',coords);
----------
 Get all the tensors in a single voxel.
 val = feGet(fe,'voxtensors',voxelIndex)
 val = feGet(fe,'voxtensors',coord)
----------
 Returns the model (M) with only a subset of columns (fibers).
 fiberList is a vector of indexes, e.g, [1 10 100]
 M = feGet(fe,'keepfibers',fiberList)
----------
 Isotropic portion of M matrix. Returns the matrix for the full model or
 for a subset of voxels.
 Miso = feGet(fe,'M iso')
 Miso = feGet(fe,'M iso',voxelsIndices)
 Miso = feGet(fe,'M iso',coords)
----------
 Total number of nodes in each voxel The voxel2FN pairs are row size
 equals number of nodes and column size is always 2. The entries of
 the first column are the fiber number. The entries in the second
 column are the node of the fiber inside the voxel.
 val = feGet(fe,'n nodes');
 val = feGet(fe,'n nodes',voxelsIndices);
 val = feGet(fe,'n nodes',coords);
----------
 Return the total number of fibers for all the voxels or in a set of
 voxels.
 nFibers = feGet(fe,'uniquefnum');           % all the voxels
 nFibers = feGet(fe,'uniquefnum',[1 2 3 4]); % for some the voxels,
                                             % specified by indexes
 nFibers = feGet(fe,'uniquefnum',coords);    % for some the voxels,
                                             % specified by coordinates
----------
 Return the indexes of the fibers for all the voxels or in a set of
 voxels.
 idxFibers = feGet(fe,'uniquef');           % all the voxels
 idxFibers = feGet(fe,'uniquef',[1 2 3 4]); % for some the voxels,
                                            % specified by indexes
 idxFibers = feGet(fe,'uniquef',coords);    % for some the voxels,
                                            % specified by coordinates
----------
 Return the total number of fibers for all the voxels or in a set of
 voxels
 nFibers = feGet(fe,'totfnum');           % all the voxels
 nFibers = feGet(fe,'totfnum',[1 2 3 4]); % for some the voxels,
                                          % specified by indexes
 nFibers = feGet(fe,'totfnum',coords);    % for some the voxels,
                                          % specified by coordinates
----------
 Return the indexes of the fibers for all the voxels or in a set of
 voxels
 idxFibers = feGet(fe,'totf');             % all the voxels
 idxFibers = feGet(fe,'totf',[1 2 3 4]);   % for some the voxels,
                                           % specified by indexes
 idxFibers = feGet(fe,'totfibers',coords); % for some the voxels,
                                           % specified by coordinates
----------
 Return the number of fibers in the model.
 nFibers = feGet(fe,'n fibers');
----------
 Weights of the isotropic voxel signals, this is the mean signal in
 each voxel.
 val = feGet(fe,'iso weights');
 val = feGet(fe,'iso weights'coords)
 val = feGet(fe,'iso weights',voxelIndices)
----------
 Weights of the fiber component. For all the fibers or a subset of
 them.
 w = feGet(fe,'fiber weights')
 w = feGet(fe,'fiber weights',fiberIndices)
----------
 Weights of the fiber component with a subset of the fibers' weights
 set to zero. This can be used to test the loss in RMSE for the
 connectome when a subset of fibers is removed, but the connectome is
 not fitted again.
 w = feGet(fe,'fiber weights test',fiberIndices)
----------
 Predicted signal (demeaned) with a subset of fibers' weights set to 0.
 This can be used to test the loss in RMSE for the connectome when a
 subset of fibers is removed, but the connectome is not fitted again.

 pSig = feGet(fe,'pSig fiber test',fiberIndices);
 pSig = feGet(fe,'pSig fiber test',fiberIndices,voxelIndices);
 pSig = feGet(fe,'pSig fiber test',fiberIndices,coords);
----------
 Measured signal in VOI, this is the raw signal. not demeaned

 dSig = feGet(fe,'dSig full')
---------
 Measured signal in VOI, demeaned, this is the signal used for the
 fiber-portion of the M model.

 dSig = feGet(fe,'dsigdemeaned');
 dSig = feGet(fe,'dsigdemeaned',[1 10 100]);
 dSig = feGet(fe,'dsigdemeaned',coords);
---------
 Get the demeaned signal for a subset of rows.
 Useful for cross-validation.
 dSig = feGet(fe,'dsigrowssubset',voxelsList);
---------
 Predicted signal of fiber alone (demeaned).
 pSig = feGet(fe,'pSig fiber');
 pSig = feGet(fe,'pSig fiber',coords);
 pSig = feGet(fe,'pSig fiber',voxelIndices);
---------
 Predicted measured signal from both fiber and iso
 pSig = feGet(fe,'pSig full')
 pSig = feGet(fe,'pSig full',coords)
 pSig = feGet(fe,'pSig full',voxelIndices)
---------
 The woxels returned by a fit of LiFE by voxel/fiber
 w = feGet(fe,'fiberweightsvoxelwise')
---------
 Predict the diffusion signal for the fiber component
 with the voxel-wise fit of LiFE
 pSig = feGet(fe,'psigfvoxelwise')
 pSig = feGet(fe,'psigfvoxelwise',coords)
 pSig = feGet(fe,'psigfvoxelwise',voxelIndices)
---------
 Predict the diffusion signal for the fiber component
 with the voxel-wise fit of LiFE, return the an array of pSigXnVoxel
 pSig = feGet(fe,'psigfvoxelwisebyvoxel')
 pSig = feGet(fe,'psigfvoxelwisebyvoxel',coords)
 pSig = feGet(fe,'psigfvoxelwisebyvoxel',voxelIndices)
---------
 The fiber and isotropic weights as a long vector
 w = feGet(fe,'fullweights')
---------
 Return the global R2 (fraction of variance explained) of the full life
 model.
 R2 = feGet(fe,'total r2');
---------
 Percent variance explained
 R2 = feGet(fe,'explained variance')
---------
 Root mean squared error of the LiFE fit to the whole data
 rmse = feGet(fe,'rmse')
---------
 Residual signal: (fiber prediction - measured_demeaned).
 res = feGet(fe,'res sig fiber')
---------
 Residual signal: (full model prediction - measured signal).
 res = feGet(fe,'res sig full');
---------
 Residual signal: (fiber model prediction - demeaned measured signal)
 with added mean signal. Res is returned as a vector.
 This is used to reconstruct an image (volume) to be used for the
 refinement process.
 res = feGet(fe,'fiber res sig with mean');
 res = feGet(fe,'fiber res sig with mean',coords);
 res = feGet(fe,'fiber res sig with mean',voxelIndices);
---------
 Residual signal fiber model prediction - demeaned measured signal
 with added mean signal. Res is returned as an array (nBvecs x nVoxel).
 This is used to reconstruct an image (volume) to be used for the
 refinement process.
 res = feGet(fe,'fiber res sig with mean voxel');
 res = feGet(fe,'fiber res sig with mean voxel',coords);
 res = feGet(fe,'fiber res sig with mean voxel',voxelIndices);
---------
 Predicted signal by the fiber model in a set of voxels.
 Vox subfield stores per voxel within the VOI. The pSig has size of the
 dwi. - It is stored as val = pSig(X,Y,Z,Theta)

 pSig = feGet(fe, 'pSig fiber by voxel');
 pSig = feGet(fe, 'pSig fiber by voxel',coords);
 pSig = feGet(fe, 'pSig fiber by voxel',voxelIndex);
---------
 Return a column vector of the proportion of variance explained in
 each voxel.
 R2byVox = feGet(fe,'voxr2');
 R2byVox = feGet(fe,'voxr2',coords);
---------
 Return a column vector of the proportion of variance explained in
 each voxel. (Normalized to the squared mean diffusion signal in each voxel)
 R2byVox = feGet(fe,'voxr2zero');
 R2byVox = feGet(fe,'voxr2zero',coords);
---------
 Return the percent of varince explained in each voxel.
 R2byVox = feGet(fe,'var exp by voxel');
 R2byVox = feGet(fe,'var exp by voxel',coords);
---------
 Demeaned diffusion signal in each voxel.
 dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel');
 dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',coords);
 dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',vxIndex);
---------
 Full (measured) signal in each voxel.
 dSigByVoxel = feGet(fe,'dSig full by Voxel');
 dSigByVoxel = feGet(fe,'dSig full by Voxel',coords);
 dSigByVoxel = feGet(fe,'dSig full by Voxel',vxIndex);
---------
 Predicted signal by the full model in a set of voxeles.
 pSigByVoxel = feGet(fe, 'pSig full by voxel');
 pSigByVoxel = feGet(fe, 'pSig full by voxel',coords);
 pSigByVoxel = feGet(fe, 'pSig full by voxel',voxelIndex);
---------
 A volume of RMSE values.
 RMSE = feGet(fe,'vox rmse')
 RMSE = feGet(fe,'vox rmse',coords)
 RMSE = feGet(fe,'vox rmse',vxIndex)
---------
 A volume of RMSE values with a subset of fibers' weights set to 0.
 RMSE = feGet(fe,'vox rmse',fiberIndices)
 RMSE = feGet(fe,'vox rmse',fiberIndices,coords)
 RMSE = feGet(fe,'vox rmse',fiberIndices,voxelIndex)
---------
 Fibers' residual signal by voxel.
 res = feGet(fe,'res sig fiber vox')
 res = feGet(fe,'res sig fiber vox',coords)
 res = feGet(fe,'res sig fiber vox',vxIndex)
---------
 Full (measured) residual signal by voxel.
 res = feGet(fe,'res sig full vox')
 res = feGet(fe,'res sig full vox',coords)
 res = feGet(fe,'res sig full vox',vxIndex)
---------
 Fibers' residual signal by voxel with mean signal added (with added
 isotropic component).
 This is used to compute the residual signal for the refinement.
 res = feGet(fe,'fiber res sig with mean vox')
 res = feGet(fe,'fiber res sig with mean vox',coords)
 res = feGet(fe,'fiber res sig with mean vox',vxIndex)
---------
 Residual signal full model prediction from a multi-voxel fit.
 res = feGet(fe,'res sig full voxfit');
 res = feGet(fe, 'res sig full voxfit',coords);
 res = feGet(fe, 'res sig full voxfit',voxelIndex);
---------
 Fiber density statistics.
 Computes the fiber density (how many fibers in each voxel)
 We compute the following values:
 (1) The number of fibers in each voxel
 (2) The number of unique fibers with non-zero weights
 (3) The sum of the weights in each voxel
 (4) The mean of the weights in each voxel
 (5) The variance of the weigths in each voxel
 pSig = feGet(fe,'fiberdensity');
---------
 Given an VOI or a set of indices to voxels returns the indices of the matching voxels inside the big
 volume, which ordinarily represents the full connectome.
 voxelIndices = feGet(fe,'voxelsindices',coords)
                IMPORTANT: Size(coords) must be Nx3;
 voxelIndices = feGet(fe,'voxelsindices',voxelIndices)
                IMPORTANT: Indices MUST be a column vector for this
                code to work. Size(voxelIndices) = Nx1;
---------
 Given an VOI finds the indices of the matching voxels inside the big
 volume, which ordinarily represents the full connectome.

 foundVoxels = feGet(fe,'find voxels',coords)

 coords is a Nx3 set of coordinates in image space
 foundVoxels is a vector of 1's and 0's, there is a one for each
 location the the connectome coordinates for which there is a match in
 the coords
---------
 Given a set of VOI coords finds the row numbers of the Model matrix
 (or equivalently the dSig vector) that represent the data for this
 set of VOI coords.
 foundVoxels = feGet(fe,'coords 2 rows',coords)
 coords      - a Nx3 set of coordinates in image space
 foundVoxels - a binary vector that is 1 for each Model matrix row
               that corresponds to at least one of the coords.
---------
 Quaternian transformation from IMAGE space to ACPC space.
 xform = feGet(fe,'xform')
---------
 Quaternian transformation from ACPC space to IMAGE space.
 xform = feGet(fe,'xform')
---------
 Dimensions of the DW volume.
 dim = feGet(fe,'dims')
---------
 Dimensions of the maps of parameters and results.
 dims = feGet(fe, 'mapsize')
---------
 Path to the 3D Anatomy Volume.
 anatomyfile = feGet(fe, 't1 file')

 End of feGet.m parameters, 
 
 Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function val = feGet(fe,param,varargin)
0002 % Get function for fascicle evaluation structure
0003 %
0004 %   val = feGet(fe,param,varargin)
0005 %
0006 %
0007 % INPUTS:
0008 %  Coords    - Nx3 set of coordinates in image space
0009 %  voxelIndices - Vector of 1's and 0's, there is a one for each
0010 %              location the the connectome coordinates for which there is
0011 %              a match in the coords
0012 %
0013 %
0014 % Copyright (2013-2014), Franco Pestilli & Brian Wandell,
0015 %  Stanford University, pestillifranco@gmail.com.
0016 %
0017 %
0018 %---------- List of arguments ----
0019 % Name of the current fe structure.
0020 % name = feGet(fe,'name')
0021 %----------
0022 % The type of objes (always, fascicle evaluation)
0023 % type = feGet(fe,'type')
0024 %----------
0025 % Structure of parameters and results from LIFE analysis
0026 % life = feGet(fe,'life')
0027 %----------
0028 % Return the connectome (fiber group) in image coordinates.
0029 % fg = feGEt(fe,'fg img')
0030 %----------
0031 % return the connectome in acpc coordinates.
0032 % fg  = feGet(fg,'fg acpc')
0033 %----------
0034 % Return the VOI comprised by the full connectome.
0035 % roi = feGet(fe,'roi')
0036 %----------
0037 % Transforms between coords for fg, roi, and dwi data
0038 % xform = feGet(fe,'xform')
0039 %----------
0040 % Load the diffusion weighted data.
0041 % dwi = feGet(fe,'dwi')
0042 %----------
0043 % Return the path to the diffusion weighted data file.
0044 % dwiFile = feGet(fe,'dwifile')
0045 %----------
0046 % Load the repeated-measure diffusion weighted data.
0047 % dwi = feGet(fe,'dwirepeat')
0048 %----------
0049 % Load the repeated measure of the diffusion weighted data.
0050 % dwiFile = feGet(fe,'dwirepeatfile')
0051 %----------
0052 % Directory where the LiFe structes are saved by defualt.
0053 % sdir = feGet(fe,'savedir');
0054 %----------
0055 % Diffusion directions.
0056 % val = feGet(fe,'bvecs');
0057 %----------
0058 % Indices to the diffusion directions in the DWi 4th Dimension.
0059 % val = feGet(fe,'bvecs indices');
0060 %----------
0061 % Number of B0's
0062 % val = feGet(fe,'n bvals');
0063 %----------
0064 % B0 Values.
0065 % bval = feGet(fe,'bvals')
0066 %----------
0067 % Returns a nVoxels X nBvecs array of measured diffusion signal
0068 % val = feGet(fe,'dsiinvox');
0069 % val = feGet(fe,'dsiinvox',voxelsIndices);
0070 % val = feGet(fe,'dsiinvox',coords);
0071 %----------
0072 % Returns a nVoxels X nBvecs array of demeaned diffusion signal
0073 % val =feGet(fe,'dsiinvoxdemeaned');
0074 % val =feGet(fe,'dsiinvoxdemeaned',voxelsIndices);
0075 % val =feGet(fe,'dsiinvoxdemeaned',coords);
0076 %----------
0077 % Get the diffusion signal at 0 diffusion weighting (B0) for this voxel
0078 % val = feGet(fe,'b0signalvoxel');
0079 % val = feGet(fe,'b0signalvoxel',voxelIndex);
0080 % val = feGet(fe,'b0signalvoxel',coords);
0081 %----------
0082 % Return a subset of fibers from the conenctome.
0083 % fg = feGet(fe,'fiberssubset',fiberList);
0084 %----------
0085 % Return the coordinates of the VOI comprised in the connectome.
0086 % Always in image space.
0087 % coords = feGet(fe,'roi coords')
0088 %----------
0089 % Number of voxels in the connectome/VOI.
0090 % nVoxels = feGet(fe,'n voxels')
0091 %----------
0092 % Indexes of actually used voxels.
0093 % These can be different than the number of voxels in the VOI in case some
0094 % voxels have no fibers in them.
0095 %
0096 % TO BE DEPRECATED.
0097 % indxUsedVx = feGet(fe,'index of used voxels')
0098 %----------
0099 % Number of actually used voxels.
0100 % This can be less than the number of voxels in the VOI in case some
0101 % voxels have no fibers in them.
0102 %
0103 % TO BE DEPRECATED.
0104 % nUsedVx = feGet(fe,'index of used voxels')
0105 %----------
0106 % Returns the first index to a voxel in the dSig vector.
0107 % The dSig vector is 1:nBvecs*nVoxels.
0108 % val = feGet(fe,'start rows')
0109 %----------
0110 % Return the rows corresponding to a set of voxels.
0111 % rows = feGet(fe,'voxel rows',idxVoxel)
0112 %----------
0113 % Return the model (M matrix), or a subset of it.
0114 % Mfiber = feGet(fe,'M fiber');
0115 % Mfiber = feGet(fe,'model',voxelsIndices);
0116 % Mfiber = feGet(fe,'model',coords);
0117 %----------
0118 % Return a subset of measurements from the fiber portion of M matrix
0119 % The rows of M are specified.  Remember that the rows refer to a
0120 % combination of voxel and measurement direction and potentially in the
0121 % future a b-value.  Hence, the rows are not specific to a voxel.
0122 % Mfiber = feGet(fe,'mfiber subset',rowsToKeep);
0123 %----------
0124 % Pairing of fibers and nodes in each voxel.
0125 % v2fnp = feGet(fe,'v2fnp');
0126 %----------
0127 % Tensors computed for each node and fiber in a set of voxels.
0128 % t = feGet(fe,'tensors')
0129 % t = feGet(fe,'tensors',voxelsIndices);
0130 % t = feGet(fe,'tensors',coords);
0131 %----------
0132 % Get all the tensors in a single voxel.
0133 % val = feGet(fe,'voxtensors',voxelIndex)
0134 % val = feGet(fe,'voxtensors',coord)
0135 %----------
0136 % Returns the model (M) with only a subset of columns (fibers).
0137 % fiberList is a vector of indexes, e.g, [1 10 100]
0138 % M = feGet(fe,'keepfibers',fiberList)
0139 %----------
0140 % Isotropic portion of M matrix. Returns the matrix for the full model or
0141 % for a subset of voxels.
0142 % Miso = feGet(fe,'M iso')
0143 % Miso = feGet(fe,'M iso',voxelsIndices)
0144 % Miso = feGet(fe,'M iso',coords)
0145 %----------
0146 % Total number of nodes in each voxel The voxel2FN pairs are row size
0147 % equals number of nodes and column size is always 2. The entries of
0148 % the first column are the fiber number. The entries in the second
0149 % column are the node of the fiber inside the voxel.
0150 % val = feGet(fe,'n nodes');
0151 % val = feGet(fe,'n nodes',voxelsIndices);
0152 % val = feGet(fe,'n nodes',coords);
0153 %----------
0154 % Return the total number of fibers for all the voxels or in a set of
0155 % voxels.
0156 % nFibers = feGet(fe,'uniquefnum');           % all the voxels
0157 % nFibers = feGet(fe,'uniquefnum',[1 2 3 4]); % for some the voxels,
0158 %                                             % specified by indexes
0159 % nFibers = feGet(fe,'uniquefnum',coords);    % for some the voxels,
0160 %                                             % specified by coordinates
0161 %----------
0162 % Return the indexes of the fibers for all the voxels or in a set of
0163 % voxels.
0164 % idxFibers = feGet(fe,'uniquef');           % all the voxels
0165 % idxFibers = feGet(fe,'uniquef',[1 2 3 4]); % for some the voxels,
0166 %                                            % specified by indexes
0167 % idxFibers = feGet(fe,'uniquef',coords);    % for some the voxels,
0168 %                                            % specified by coordinates
0169 %----------
0170 % Return the total number of fibers for all the voxels or in a set of
0171 % voxels
0172 % nFibers = feGet(fe,'totfnum');           % all the voxels
0173 % nFibers = feGet(fe,'totfnum',[1 2 3 4]); % for some the voxels,
0174 %                                          % specified by indexes
0175 % nFibers = feGet(fe,'totfnum',coords);    % for some the voxels,
0176 %                                          % specified by coordinates
0177 %----------
0178 % Return the indexes of the fibers for all the voxels or in a set of
0179 % voxels
0180 % idxFibers = feGet(fe,'totf');             % all the voxels
0181 % idxFibers = feGet(fe,'totf',[1 2 3 4]);   % for some the voxels,
0182 %                                           % specified by indexes
0183 % idxFibers = feGet(fe,'totfibers',coords); % for some the voxels,
0184 %                                           % specified by coordinates
0185 %----------
0186 % Return the number of fibers in the model.
0187 % nFibers = feGet(fe,'n fibers');
0188 %----------
0189 % Weights of the isotropic voxel signals, this is the mean signal in
0190 % each voxel.
0191 % val = feGet(fe,'iso weights');
0192 % val = feGet(fe,'iso weights'coords)
0193 % val = feGet(fe,'iso weights',voxelIndices)
0194 %----------
0195 % Weights of the fiber component. For all the fibers or a subset of
0196 % them.
0197 % w = feGet(fe,'fiber weights')
0198 % w = feGet(fe,'fiber weights',fiberIndices)
0199 %----------
0200 % Weights of the fiber component with a subset of the fibers' weights
0201 % set to zero. This can be used to test the loss in RMSE for the
0202 % connectome when a subset of fibers is removed, but the connectome is
0203 % not fitted again.
0204 % w = feGet(fe,'fiber weights test',fiberIndices)
0205 %----------
0206 % Predicted signal (demeaned) with a subset of fibers' weights set to 0.
0207 % This can be used to test the loss in RMSE for the connectome when a
0208 % subset of fibers is removed, but the connectome is not fitted again.
0209 %
0210 % pSig = feGet(fe,'pSig fiber test',fiberIndices);
0211 % pSig = feGet(fe,'pSig fiber test',fiberIndices,voxelIndices);
0212 % pSig = feGet(fe,'pSig fiber test',fiberIndices,coords);
0213 %----------
0214 % Measured signal in VOI, this is the raw signal. not demeaned
0215 %
0216 % dSig = feGet(fe,'dSig full')
0217 %---------
0218 % Measured signal in VOI, demeaned, this is the signal used for the
0219 % fiber-portion of the M model.
0220 %
0221 % dSig = feGet(fe,'dsigdemeaned');
0222 % dSig = feGet(fe,'dsigdemeaned',[1 10 100]);
0223 % dSig = feGet(fe,'dsigdemeaned',coords);
0224 %---------
0225 % Get the demeaned signal for a subset of rows.
0226 % Useful for cross-validation.
0227 % dSig = feGet(fe,'dsigrowssubset',voxelsList);
0228 %---------
0229 % Predicted signal of fiber alone (demeaned).
0230 % pSig = feGet(fe,'pSig fiber');
0231 % pSig = feGet(fe,'pSig fiber',coords);
0232 % pSig = feGet(fe,'pSig fiber',voxelIndices);
0233 %---------
0234 % Predicted measured signal from both fiber and iso
0235 % pSig = feGet(fe,'pSig full')
0236 % pSig = feGet(fe,'pSig full',coords)
0237 % pSig = feGet(fe,'pSig full',voxelIndices)
0238 %---------
0239 % The woxels returned by a fit of LiFE by voxel/fiber
0240 % w = feGet(fe,'fiberweightsvoxelwise')
0241 %---------
0242 % Predict the diffusion signal for the fiber component
0243 % with the voxel-wise fit of LiFE
0244 % pSig = feGet(fe,'psigfvoxelwise')
0245 % pSig = feGet(fe,'psigfvoxelwise',coords)
0246 % pSig = feGet(fe,'psigfvoxelwise',voxelIndices)
0247 %---------
0248 % Predict the diffusion signal for the fiber component
0249 % with the voxel-wise fit of LiFE, return the an array of pSigXnVoxel
0250 % pSig = feGet(fe,'psigfvoxelwisebyvoxel')
0251 % pSig = feGet(fe,'psigfvoxelwisebyvoxel',coords)
0252 % pSig = feGet(fe,'psigfvoxelwisebyvoxel',voxelIndices)
0253 %---------
0254 % The fiber and isotropic weights as a long vector
0255 % w = feGet(fe,'fullweights')
0256 %---------
0257 % Return the global R2 (fraction of variance explained) of the full life
0258 % model.
0259 % R2 = feGet(fe,'total r2');
0260 %---------
0261 % Percent variance explained
0262 % R2 = feGet(fe,'explained variance')
0263 %---------
0264 % Root mean squared error of the LiFE fit to the whole data
0265 % rmse = feGet(fe,'rmse')
0266 %---------
0267 % Residual signal: (fiber prediction - measured_demeaned).
0268 % res = feGet(fe,'res sig fiber')
0269 %---------
0270 % Residual signal: (full model prediction - measured signal).
0271 % res = feGet(fe,'res sig full');
0272 %---------
0273 % Residual signal: (fiber model prediction - demeaned measured signal)
0274 % with added mean signal. Res is returned as a vector.
0275 % This is used to reconstruct an image (volume) to be used for the
0276 % refinement process.
0277 % res = feGet(fe,'fiber res sig with mean');
0278 % res = feGet(fe,'fiber res sig with mean',coords);
0279 % res = feGet(fe,'fiber res sig with mean',voxelIndices);
0280 %---------
0281 % Residual signal fiber model prediction - demeaned measured signal
0282 % with added mean signal. Res is returned as an array (nBvecs x nVoxel).
0283 % This is used to reconstruct an image (volume) to be used for the
0284 % refinement process.
0285 % res = feGet(fe,'fiber res sig with mean voxel');
0286 % res = feGet(fe,'fiber res sig with mean voxel',coords);
0287 % res = feGet(fe,'fiber res sig with mean voxel',voxelIndices);
0288 %---------
0289 % Predicted signal by the fiber model in a set of voxels.
0290 % Vox subfield stores per voxel within the VOI. The pSig has size of the
0291 % dwi. - It is stored as val = pSig(X,Y,Z,Theta)
0292 %
0293 % pSig = feGet(fe, 'pSig fiber by voxel');
0294 % pSig = feGet(fe, 'pSig fiber by voxel',coords);
0295 % pSig = feGet(fe, 'pSig fiber by voxel',voxelIndex);
0296 %---------
0297 % Return a column vector of the proportion of variance explained in
0298 % each voxel.
0299 % R2byVox = feGet(fe,'voxr2');
0300 % R2byVox = feGet(fe,'voxr2',coords);
0301 %---------
0302 % Return a column vector of the proportion of variance explained in
0303 % each voxel. (Normalized to the squared mean diffusion signal in each voxel)
0304 % R2byVox = feGet(fe,'voxr2zero');
0305 % R2byVox = feGet(fe,'voxr2zero',coords);
0306 %---------
0307 % Return the percent of varince explained in each voxel.
0308 % R2byVox = feGet(fe,'var exp by voxel');
0309 % R2byVox = feGet(fe,'var exp by voxel',coords);
0310 %---------
0311 % Demeaned diffusion signal in each voxel.
0312 % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel');
0313 % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',coords);
0314 % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',vxIndex);
0315 %---------
0316 % Full (measured) signal in each voxel.
0317 % dSigByVoxel = feGet(fe,'dSig full by Voxel');
0318 % dSigByVoxel = feGet(fe,'dSig full by Voxel',coords);
0319 % dSigByVoxel = feGet(fe,'dSig full by Voxel',vxIndex);
0320 %---------
0321 % Predicted signal by the full model in a set of voxeles.
0322 % pSigByVoxel = feGet(fe, 'pSig full by voxel');
0323 % pSigByVoxel = feGet(fe, 'pSig full by voxel',coords);
0324 % pSigByVoxel = feGet(fe, 'pSig full by voxel',voxelIndex);
0325 %---------
0326 % A volume of RMSE values.
0327 % RMSE = feGet(fe,'vox rmse')
0328 % RMSE = feGet(fe,'vox rmse',coords)
0329 % RMSE = feGet(fe,'vox rmse',vxIndex)
0330 %---------
0331 % A volume of RMSE values with a subset of fibers' weights set to 0.
0332 % RMSE = feGet(fe,'vox rmse',fiberIndices)
0333 % RMSE = feGet(fe,'vox rmse',fiberIndices,coords)
0334 % RMSE = feGet(fe,'vox rmse',fiberIndices,voxelIndex)
0335 %---------
0336 % Fibers' residual signal by voxel.
0337 % res = feGet(fe,'res sig fiber vox')
0338 % res = feGet(fe,'res sig fiber vox',coords)
0339 % res = feGet(fe,'res sig fiber vox',vxIndex)
0340 %---------
0341 % Full (measured) residual signal by voxel.
0342 % res = feGet(fe,'res sig full vox')
0343 % res = feGet(fe,'res sig full vox',coords)
0344 % res = feGet(fe,'res sig full vox',vxIndex)
0345 %---------
0346 % Fibers' residual signal by voxel with mean signal added (with added
0347 % isotropic component).
0348 % This is used to compute the residual signal for the refinement.
0349 % res = feGet(fe,'fiber res sig with mean vox')
0350 % res = feGet(fe,'fiber res sig with mean vox',coords)
0351 % res = feGet(fe,'fiber res sig with mean vox',vxIndex)
0352 %---------
0353 % Residual signal full model prediction from a multi-voxel fit.
0354 % res = feGet(fe,'res sig full voxfit');
0355 % res = feGet(fe, 'res sig full voxfit',coords);
0356 % res = feGet(fe, 'res sig full voxfit',voxelIndex);
0357 %---------
0358 % Fiber density statistics.
0359 % Computes the fiber density (how many fibers in each voxel)
0360 % We compute the following values:
0361 % (1) The number of fibers in each voxel
0362 % (2) The number of unique fibers with non-zero weights
0363 % (3) The sum of the weights in each voxel
0364 % (4) The mean of the weights in each voxel
0365 % (5) The variance of the weigths in each voxel
0366 % pSig = feGet(fe,'fiberdensity');
0367 %---------
0368 % Given an VOI or a set of indices to voxels returns the indices of the matching voxels inside the big
0369 % volume, which ordinarily represents the full connectome.
0370 % voxelIndices = feGet(fe,'voxelsindices',coords)
0371 %                IMPORTANT: Size(coords) must be Nx3;
0372 % voxelIndices = feGet(fe,'voxelsindices',voxelIndices)
0373 %                IMPORTANT: Indices MUST be a column vector for this
0374 %                code to work. Size(voxelIndices) = Nx1;
0375 %---------
0376 % Given an VOI finds the indices of the matching voxels inside the big
0377 % volume, which ordinarily represents the full connectome.
0378 %
0379 % foundVoxels = feGet(fe,'find voxels',coords)
0380 %
0381 % coords is a Nx3 set of coordinates in image space
0382 % foundVoxels is a vector of 1's and 0's, there is a one for each
0383 % location the the connectome coordinates for which there is a match in
0384 % the coords
0385 %---------
0386 % Given a set of VOI coords finds the row numbers of the Model matrix
0387 % (or equivalently the dSig vector) that represent the data for this
0388 % set of VOI coords.
0389 % foundVoxels = feGet(fe,'coords 2 rows',coords)
0390 % coords      - a Nx3 set of coordinates in image space
0391 % foundVoxels - a binary vector that is 1 for each Model matrix row
0392 %               that corresponds to at least one of the coords.
0393 %---------
0394 % Quaternian transformation from IMAGE space to ACPC space.
0395 % xform = feGet(fe,'xform')
0396 %---------
0397 % Quaternian transformation from ACPC space to IMAGE space.
0398 % xform = feGet(fe,'xform')
0399 %---------
0400 % Dimensions of the DW volume.
0401 % dim = feGet(fe,'dims')
0402 %---------
0403 % Dimensions of the maps of parameters and results.
0404 % dims = feGet(fe, 'mapsize')
0405 %---------
0406 % Path to the 3D Anatomy Volume.
0407 % anatomyfile = feGet(fe, 't1 file')
0408 %
0409 % End of feGet.m parameters,
0410 %
0411 % Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.
0412    
0413 val = [];
0414 
0415 % Format the input parameters.
0416 param = lower(strrep(param,' ',''));
0417 
0418 % Start sorting the input and computing the output.
0419 switch param
0420   case 'name'
0421     % Name of the current fe structure.
0422     %
0423     % name = feGet(fe,'name')
0424     val = fe.name;
0425     
0426   case 'type'
0427     % The type of objes (always, fascicle evaluation)
0428     %
0429     % type = feGet(fe,'type')
0430     val = fe.type; % Always fascicle evaluation
0431     
0432     % Set top level structure, not just single slot
0433   case 'life'
0434     % Structure of parameters and results from LIFE analysis
0435     %
0436     % life = feGet(fe,'life')
0437     val = fe.life; 
0438     
0439   case {'fgimg','fibersimg'}
0440     % Return the connectome (fiber group) in image coordinates.
0441     %
0442     % fg = feGet(fe,'fg img')
0443     val = fe.fg;  % Fiber group candidate fascicles, uses fgSet/Get
0444     
0445   case {'fgacpc','fibersacpc'}
0446     % return the connectome in acpc coordinates.
0447     %
0448     % fg  = feGet(fg,'fg acpc')
0449     xform = feGet(fe,'img2acpcxform');
0450     val   = dtiXformFiberCoords(feGet(fe,'fgimg'),xform,'acpc');
0451     
0452   case 'roi'
0453     % Return the VOI comprised by the full connectome.
0454     %
0455     % roi = feGet(fe,'roi')
0456     val = fe.roi;
0457     
0458   case 'roiacpc'
0459     % Return the VOI comprised by the full connectome.
0460     %
0461     % roi = feGet(fe,'roi acpc')
0462     name   = sprintf('roi_%s',fe.fg.name); 
0463     randColor = rand(1,3);
0464     val = dtiNewRoi(name,randColor,fefgGet(feGet(fe,'fg acpc'),'unique image coords'));
0465     
0466   case 'xform'
0467     % Transforms between coords for fg, roi, and dwi data
0468     %
0469     % xform = feGet(fe,'xform')
0470     val = fe.life.xform;
0471     
0472   case 'dwi'
0473     %  Load the diffusion weighted data.
0474     %
0475     % dwi = feGet(fe,'dwi')
0476     val = dwiLoad(feGet(fe,'dwifile'));
0477   
0478   case 'dwirepeat'
0479     %  Load the diffusion weighted data.
0480     %
0481     % dwi = feGet(fe,'dwirepeat')
0482     val = dwiLoad(feGetRep(fe,'dwifile'));
0483     
0484   case 'dwifile'
0485     %  Load the diffusion weighted data.
0486     %
0487     % dwiFile = feGet(fe,'dwifile')
0488     val = fe.path.dwifile;
0489     
0490   case 'dwifilerep'
0491     %  Load the diffusion weighted data.
0492     %
0493     % dwiFile = feGet(fe,'dwifilerep')
0494     val = fe.path.dwifilerep;
0495  
0496   case 'savedir'
0497     %  Directory where the LiFe structes are saved by defualt.
0498     %
0499     % sdir = feGet(fe,'savedir');
0500     val = fe.path.savedir;
0501     
0502   case {'bvecs'}
0503     % Diffusion directions.
0504     %
0505     % val = feGet(fe,'bvecs');
0506     val = fe.life.bvecs;
0507     
0508   case {'bvecsindices'}
0509     % Indices to the diffusion directions in the DWi 4th Dimension.
0510     %
0511     % val = feGet(fe,'bvecs indices');
0512     val = fe.life.bvecsindices;
0513     
0514   case {'nbvecs','nbvals'}
0515     % Number of B0's
0516     %
0517     % val = feGet(fe,'n bvals');
0518     val = length(feGet(fe,'bvals'));
0519     
0520   case {'bvals'}
0521     % B0 Values.
0522     %
0523     % bval = feGet(fe,'bvals')
0524     val = fe.life.bvals;
0525     
0526   case {'diffusionsignalinvoxel','dsiinvox','dsigvox','dsigmeasuredvoxel'}
0527     % Returns a nVoxels X nBvecs array of measured diffusion signal
0528     %
0529     % val = feGet(fe,'dsiinvox');
0530     % val = feGet(fe,'dsiinvox',voxelsIndices);
0531     % val = feGet(fe,'dsiinvox',coords);
0532     val = fe.life.diffusion_signal_img(feGet(fe,'voxelsindices',varargin),:)';
0533     
0534   case {'diffusionsignalinvoxeldemeaned','dsiinvoxdemeaned'}
0535     % Returns a nVoxels X nBvecs array of demeaned diffusion signal
0536     %
0537     % val =feGet(fe,'dsiinvoxdemeaned');
0538     % val =feGet(fe,'dsiinvoxdemeaned',voxelsIndices);
0539     % val =feGet(fe,'dsiinvoxdemeaned',coords);
0540     nBvecs     = feGet(fe,'nBvecs');
0541     voxelIndices = feGet(fe,'voxelsindices',varargin);
0542     val = fe.life.diffusion_signal_img(voxelIndices,:) - repmat(mean(fe.life.diffusion_signal_img(voxelIndices,:), 2),1,nBvecs);
0543     keyboard
0544     % THis seems to be wrong
0545     
0546   case {'b0signalimage','b0vox'}
0547     % Get the diffusion signal at 0 diffusion weighting (B0) for this voxel
0548     %
0549     % val = feGet(fe,'b0signalvoxel');
0550     % val = feGet(fe,'b0signalvoxel',voxelIndex);
0551     % val = feGet(fe,'b0signalvoxel',coords);
0552     val = fe.life.diffusion_S0_img(feGet(fe,'voxelsindices',varargin), :);
0553     
0554   case {'fiberssubset','fsub','subsetoffibers','fgsubset'}
0555     % Return a subset of fibers from the conenctome.
0556     %
0557     % fg = feGet(fe,'fiberssubset',fiberList);
0558     val = feGet(fe,'fg img');
0559     fiberList = varargin{1};
0560     fibers = cell(size(fiberList));
0561     for ff = 1:length(fiberList)
0562       fibers{ff} = val.fibers{fiberList(ff)};
0563       if isfield(val,'pathwayInfo')
0564         pathInfo(ff) = val.pathwayInfo(fiberList(ff));
0565       end
0566     end
0567     val.fibers = fibers;
0568     if isfield(val,'pathwayInfo')
0569       val.pathwayInfo = pathInfo;
0570     end
0571     val.name = sprintf('subsetFrom:%s',val.name);
0572     
0573   case {'roivoxels','roicoords'}
0574     % Return the coordinates of the VOI comprised in the connectome.
0575     % Always in image space.
0576     %
0577     % coords = feGet(fe,'roi coords')
0578     val = fe.roi.coords;
0579   
0580   case {'roicoordssubset'}
0581     % Return the coordinates of the VOI comprised in the connectome.
0582     % Always in image space.
0583     %
0584     % coords = feGet(fe,'roi coords')
0585     val = feGet(fe,'roi coords');
0586     val = val(varargin{1},:);
0587   
0588   case {'nroivoxels','nvoxels'}
0589     % Number of voxels in the connectome/VOI.
0590     %
0591     % nVoxels = feGet(fe,'n voxels')
0592     val = size(feGet(fe,'roivoxels'),1);
0593     
0594   case {'usedvoxels','indexesofusedvoxels'}
0595     % Indexes of actually used voxels.
0596     %
0597     % These can be different than the number of voxels in the VOI in case some
0598     % voxels have no fibers in them.
0599     %
0600     % TO BE DEPRECATED.
0601     %
0602     % indxUsedVx = feGet(fe,'index of used voxels')
0603     val = find(feGet(fe,'nnodes'));
0604     
0605   case {'nusedvoxels','numberofusedvoxels'}
0606     % Number of actually used voxels.
0607     %
0608     % This can be less than the number of voxels in the VOI in case some
0609     % voxels have no fibers in them.
0610     %
0611     % TO BE DEPRECATED.
0612     %
0613     % nUsedVx = feGet(fe,'index of used voxels')
0614     val = size(feGet(fe,'used voxels'),2);
0615     
0616   case {'startrow','first index into the dsig vector for a voxel'}
0617     % Returns the first index to a voxel in the dSig vector.
0618     %
0619     % The dSig vector is 1:nBvecs*nVoxels.
0620     %
0621     % val = feGet(fe,'start rows')
0622     val = (varargin{1}-1)*feGet(fe,'nBvecs') + 1;
0623     
0624   case {'voxelrows','all indexes into the dsig vector for a set of voxels'}
0625     % Return the rows corresponding to a set of voxels.
0626     %
0627     % rows = feGet(fe,'voxel rows',idxVoxel)
0628     n        = feGet(fe,'n voxels');
0629     nBvecs   = feGet(fe,'n bvecs');
0630     voxelsToKeep = zeros(n,1); voxelsToKeep(varargin{1}) = 1;
0631     val = logical(kron(voxelsToKeep(:),ones(nBvecs,1)));
0632     
0633   case {'modeltensor'}
0634     val = fe.life.modelTensor;
0635     
0636   case {'mfiber','m','model'}
0637     % Return the model (M matrix), or a subset of it.
0638     %
0639     % Mfiber = feGet(fe,'M fiber');
0640     % Mfiber = feGet(fe,'model',voxelsIndices);
0641     % Mfiber = feGet(fe,'model',coords);
0642     
0643     % idxVoxels is an integer list of the voxels to retain
0644     % If idxVoxels is not included, return the whole matrix
0645     % M contains only the rows for the specified voxels (all directions)
0646     if isempty(varargin)
0647       % Return the whole M matrix
0648       val = fe.life.Mfiber;
0649     else
0650       % Return only the rows for the specified voxels, including all
0651       % directions.
0652       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
0653       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
0654       % val = fe.life.Mfiber(voxelRowsToKeep,:);
0655       val = fe.life.Mfiber(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)),:);
0656     end
0657     
0658   case {'mfibervoxelsubset','indexedafiber','mfiberindexed'}
0659     % Return a subset of measurements from the fiber portion of M matrix
0660     % The rows of M are specified.  Remember that the rows refer to a
0661     % combination of voxel and measurement direction and potentially in the
0662     % future a b-value.  Hence, the rows are not specific to a voxel.
0663     %
0664     % Mfiber = feGet(fe,'mfiber subset',rowsToKeep);
0665     
0666     if isempty(varargin), error('Subset of rows must be specified'); end
0667     val = fe.life.Mfiber(varargin{1},:);
0668     
0669   case {'msubsetfibers','mfiberssubset','mkeepfibers'}
0670     % Returns the model (M) with only a subset of columns (fibers).
0671     %
0672     % fiberList is a vector of indexes, e.g, [1 10 100]
0673     %
0674     % M = feGet(fe,'mkeepfibers',fiberList)
0675     val = fe.life.Mfiber(:,varargin{1});
0676     
0677   case {'miso'}
0678     % Isotropic portion of M matrix
0679     % returns the matrix for the full model or for a subset of voxels
0680     %
0681     % Miso = feGet(fe,'M iso')
0682     % Miso = feGet(fe,'M iso',voxelsIndices)
0683     % Miso = feGet(fe,'M iso',coords)
0684     if isempty(varargin)
0685       % Return the whole M iso
0686       val = feBuildSparseBlockDiag(feGet(fe,'nBvecs'),feGet(fe,'nVoxels'));
0687     else
0688       val = feBuildSparseBlockDiag(feGet(fe,'nBvecs'),length(feGet(fe,'voxelsindices',varargin)));
0689     end
0690     
0691   case {'voxel2fnpair','voxel2fibernodepair','v2fnp'}
0692     % Pairing of fibers and nodes in each voxel.
0693     %
0694     % v2fnp = feGet(fe,'v2fnp');
0695     if isempty(fe.life.voxel2FNpair)
0696       fprintf('[%s] fe.life.voxel2FNpair is empty, can be computed as: \nfe = feSet(fe,''v2fnp'',feGet(fe,''fg img''),''v2fn'',feGet(fe,''roi coords'')',mfilename);
0697       return
0698     end
0699     val = fe.life.voxel2FNpair;
0700     
0701   case {'tensors','fibers tensors'}
0702     % Tensors computed for each node and fiber in a set of voxels.
0703     %
0704     % t = feGet(fe,'tensors')
0705     % t = feGet(fe,'tensors',voxelsIndices);
0706     % t = feGet(fe,'tensors',coords);
0707     if isempty(varargin)
0708       val = fe.life.fibers.tensors;
0709     else
0710       vv = feGet(fe,'voxelsindices',varargin);
0711       val = cell(size(vv));
0712       for ff = 1:length(vv)
0713         val{ff} = fe.life.fibers.tensors{vv(ff)};
0714       end
0715     end
0716     
0717   case {'voxeltensors','voxtensors','voxq'}
0718     % Get all the tensors in a signle voxel
0719     %
0720     % val = feGet(fe,'voxtensors',voxelIndex)
0721     % val = feGet(fe,'voxtensors',coord)
0722     
0723     % Index for the voxel
0724     vv = feGet(fe,'voxelsindices',varargin);
0725     
0726     % The indexes of the voxeles used, to build LiFE.
0727     usedVoxels = feGet(fe,'usedVoxels');
0728     voxIndex   = usedVoxels(vv);
0729     nNodes     = feGet(fe,'nNodes');
0730     
0731     % Get the tensors for each node in each fiber going through this voxel:
0732     val = zeros(nNodes(voxIndex), 9); % Allocate space for all the tensors (9 is for the 3 x 3 tensor components)
0733     for ii = 1:nNodes(voxIndex)           % Get the tensors
0734       val(ii,:) = fe.life.fibers.tensors{fe.life.voxel2FNpair{voxIndex}(ii,1)} ...
0735         (fe.life.voxel2FNpair{voxIndex}(ii,2),:);
0736     end
0737     
0738   case {'nnodes','numofnodes'}
0739     % Total number of nodes in each voxel The voxel2FN pairs are row size
0740     % equals number of nodes and column size is always 2. The entries of
0741     % the first column are the fiber number. The entries in the second
0742     % column are the node of the fiber inside the voxel.
0743     %
0744     % val = feGet(fe,'n nodes');
0745     % val = feGet(fe,'n nodes',voxelsIndices);
0746     % val = feGet(fe,'n nodes',coords);
0747     if ~isempty(fe.life.voxel2FNpair)
0748         [val, ~] = cellfun(@size,fe.life.voxel2FNpair);
0749         val      = val(feGet(fe,'voxelsindices',varargin));
0750     end
0751 
0752   case {'numberofuniquefibersbyvoxel','uniquefnum'}
0753     % Return the total number of fibers for all the voxels or in a set of
0754     % voxels
0755     %
0756     % nFibers = feGet(fe,'uniquefnum');           % all the voxels
0757     % nFibers = feGet(fe,'uniquefnum',[1 2 3 4]); % for some the voxels,
0758     %                                             % specified by indexes
0759     % nFibers = feGet(fe,'uniquefnum',coords);    % for some the voxels,
0760     %                                             % specified by coordinates
0761     val = fe.life.fibers.unique.num(feGet(fe,'voxelsindices',varargin));
0762     
0763   case {'indextouniquefibersbyvoxel','uniquef'}
0764     % Return the indexes of the fibers for all the voxels or in a set of
0765     % voxels.
0766     %
0767     % idxFibers = feGet(fe,'uniquef');           % all the voxels
0768     % idxFibers = feGet(fe,'uniquef',[1 2 3 4]); % for some the voxels,
0769     %                                            % specified by indexes
0770     % idxFibers = feGet(fe,'uniquef',coords);    % for some the voxels,
0771     %                                            % specified by coordinates
0772     vxIndex = feGet(fe,'voxels indices',varargin);
0773     val = cell(length(vxIndex),1);
0774     for ii = 1:length(vxIndex)
0775       val{ii} = fe.life.fibers.unique.index{vxIndex(ii)};
0776     end
0777     
0778   case {'numberoftotalfibersbyvoxels','totfnum'}
0779     % Return the total number of fibers for all the voxels or in a set of
0780     % voxels
0781     %
0782     % nFibers = feGet(fe,'totfnum');           % all the voxels
0783     % nFibers = feGet(fe,'totfnum',[1 2 3 4]); % for some the voxels,
0784     %                                          % specified by indexes
0785     % nFibers = feGet(fe,'totfnum',coords);    % for some the voxels,
0786     %                                          % specified by coordinates
0787     val = fe.life.fibers.total.num(feGet(fe,'voxels indices',varargin));
0788     
0789   case {'indexoftotalfibersbuvoxel','totf'}
0790     % Return the indexes of the fibers for all the voxels or in a set of
0791     % voxels
0792     %
0793     % idxFibers = feGet(fe,'totf');             % all the voxels
0794     % idxFibers = feGet(fe,'totf',[1 2 3 4]);   % for some the voxels,
0795     %                                           % specified by indexes
0796     % idxFibers = feGet(fe,'totfibers',coords); % for some the voxels,
0797     %                                           % specified by coordinates
0798     vxIndex = feGet(fe,'voxels indices',varargin);
0799     val = cell(length(vxIndex),1);
0800     for ii = 1:length(vxIndex)
0801       val{ii} = fe.life.fibers.total.index{vxIndex(ii)};
0802     end
0803     
0804   case {'nfibers'}
0805     % Return the number of fibers in the model.
0806     %
0807     % nFibers = feGet(fe,'n fibers')
0808     val = size(fe.life.Mfiber,2);
0809     
0810   case {'isoweights','weightsiso','meanvoxelsignal'}
0811     % Weights of the isotropic voxel signals, this is the mean signal in
0812     % each voxel.
0813     %
0814     % val = feGet(fe,'iso weights');
0815     % val = feGet(fe,'iso weights'coords)
0816     % val = feGet(fe,'iso weights',voxelIndices)
0817     val = feGet(fe,'Miso') \ feGet(fe,'dsig full')';
0818     val = val(feGet(fe,'voxelsindices',varargin));
0819      
0820   case {'voxisoweights','voxweightsiso','voxmeanvoxelsignal'}
0821     % Weights of the isotropic voxel signals, this is the mean signal in
0822     % each voxel.
0823     % Organized nBvecs x nVoxels
0824     %
0825     % val = feGet(fe,'iso weights');
0826     % val = feGet(fe,'iso weights'coords)
0827     % val = feGet(fe,'iso weights',voxelIndices)
0828     val = feGet(fe,'Miso') \ feGet(fe,'dsig full')';
0829     val = repmat(val,1,feGet(fe,'nbvecs'))';
0830 
0831     if ~isempty(varargin)
0832       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
0833       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
0834       % val           = val(voxelRowsToKeep,:);
0835       val = val(:,feGet(fe,'voxelsindices',varargin));
0836     end
0837 
0838   case {'dsigiso','isodsig'}
0839     % mean signalin each voxel, returned for each diffusion direction:
0840     % size(nBvecsxnVoxels, 1).
0841     %
0842     % val = feGet(fe,'iso disg');
0843     % val = feGet(fe,'iso disg',coords)
0844     % val = feGet(fe,'iso dsig',voxelIndices)
0845     val = feGet(fe,'iso weights');
0846     val = repmat(val,1,feGet(fe,'nbvecs'))';
0847     val = val(:);
0848     
0849   case {'fiberweights'}
0850     % Weights of the fiber component. For all the fibers or a subset of
0851     % them.
0852     %
0853     % w = feGet(fe,'fiber weights')
0854     % w = feGet(fe,'fiber weights',fiberIndices)
0855 
0856     % If the model was not fit yet, fit it, install the fit and then return
0857     % the weights.
0858     if ~isfield(fe.life,'fit')
0859       fprintf('[%s] fe.life.fit is empty, can be computed as: \nfeSet(fe,''fit'',feFitModel(feGet(fe,''Mfiber''), feGet(fe,''dsigdemeaned''),''sgdnn''))',mfilename);
0860       return
0861     end
0862     
0863     % Get the weights
0864     if ~isempty(varargin) % subselect the weights for the requested fibers
0865       val = fe.life.fit.weights(varargin{1});  
0866     else % Return all of them
0867       val = fe.life.fit.weights;
0868     end
0869     
0870   case {'fiberweightstest'}
0871     % Weights of the fiber component with a subset of the fibers' weigth
0872     % set to zero. This can be used to test the loss in RMSE for the
0873     % connectome when a subset of fibers is removed, but the connectome is
0874     % not fitted again.
0875     %
0876     % w = feGet(fe,'fiber weights test',fiberIndices)
0877 
0878     % If the model was not fit yet, fit it, install the fit and then return
0879     % the weights.
0880     if ~isfield(fe.life,'fit')
0881       fprintf('[%s] fe.life.fit is empty, can be computed as: \nfeSet(fe,''fit'',feFitModel(feGet(fe,''Mfiber''), feGet(fe,''dsigdemeaned''),''sgdnn''))',mfilename);
0882       return
0883     end
0884     
0885     % Get the weights
0886     if ~isempty(varargin) % subselect the weights for the requested fibers
0887       val = fe.life.fit.weights;  
0888       val(varargin{1}) = 0;
0889     else % A set of fiber weights is required as input
0890       error('[%s] Indices to a subset of fiber-weights must be passed in w = feGet(fe,''fiber weights test'',fiberIndices))',mfilename);
0891     end
0892     
0893     case {'fiberweightstestvoxelwise'}
0894     % Weights of the fiber component with a subset of the fibers' weigth
0895     % set to zero. This can be used to test the loss in RMSE for the
0896     % connectome when a subset of fibers is removed, but the connectome is
0897     % not fitted again.
0898     %
0899     % w = feGet(fe,'fiber weights test voxel wise',fiberIndices)
0900 
0901     % If the model was not fit yet, fit it, install the fit and then return
0902     % the weights.
0903     if ~isfield(fe.life,'voxfit')
0904       fprintf('[%s] fe.life.fit is empty, can be computed as: \nfeSet(fe,''fit'',feFitModel(feGet(fe,''Mfiber''), feGet(fe,''dsigdemeaned''),''sgdnn''))',mfilename);
0905       return
0906     end
0907     
0908     % Get the weights
0909     if ~isempty(varargin) % subselect the weights for the requested fibers
0910       val = fe.life.voxfit.weights;  
0911       val(:,varargin{1}) = 0;
0912     else % A set of fiber weights is required as input
0913       error('[%s] Indices to a subset of fiber-weights must be passed in\nw = feGet(fe,''fiber weights test voxel wise'',fiberIndices))',mfilename);
0914     end
0915     
0916   case {'dsigmeasured','dsigfull'}
0917     % Measured signal in VOI, this is the raw signal. not demeaned
0918     %
0919     % dSig = feGet(fe,'dSig full')
0920     val = fe.life.dSig;
0921     % Return a subset of voxels
0922     if ~isempty(varargin)
0923       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
0924       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
0925       % val              = val(voxelRowsToKeep,:);
0926       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
0927     end
0928     
0929   case {'diffusionsignaldemeaned','dsigdemeaned'}
0930     % Measured signal in VOI, demeaned, this is the signal used for the
0931     % fiber-portion of the M model.
0932     %
0933     % dSig = feGet(fe,'dsigdemeaned');
0934     % dSig = feGet(fe,'dsigdemeaned',[1 10 100]);
0935     % dSig = feGet(fe,'dsigdemeaned',coords);
0936     nVoxels = feGet(fe,'nVoxels');
0937     nBvecs  = feGet(fe,'nBvecs');
0938     val     = (fe.life.dSig - reshape(repmat( ...
0939       mean(reshape(fe.life.dSig, nBvecs, nVoxels),1),...
0940       nBvecs,1), size(fe.life.dSig)))';
0941     % Return a subset of voxels
0942     if ~isempty(varargin)
0943       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
0944       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
0945       % val           = val(voxelRowsToKeep,:);
0946       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
0947     end
0948     
0949   case {'dsigrowssubset','diffusionsignaldemeanedinsubsetofrows'}
0950     % Get the demeaned signal for a subset of rows.
0951     % Useful for cross-validation.
0952     %
0953     % dSig = feGet(fe,'dsigrowssubset',voxelsList);
0954     dSig = feGet(fe,'dsigdemeaned');
0955     for vv = 1:length(voxelsList)
0956       val(feGet(fe,'voxel rows',vv)) = dSig(feGet(fe,'voxel rows',voxelList(vv)));
0957     end
0958     
0959   case {'psigfiber', 'fiberpsig','fiberpredicted','dsigpredictedfiber'}
0960     % Predicted signal of fiber alone (demeaned).
0961     %
0962     % pSig = feGet(fe,'pSig fiber');
0963     % pSig = feGet(fe,'pSig fiber',coords);
0964     % pSig = feGet(fe,'pSig fiber',voxelIndices);
0965     val = feGet(fe,'Mfiber')*feGet(fe,'fiber weights');
0966     if ~isempty(varargin)
0967       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
0968       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
0969       % val           = val(voxelRowsToKeep,:);
0970       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
0971     end
0972     
0973   case {'uniquefibersindicesinroi'}
0974     % Find the unique fibers indices in the FE roi.
0975     % Thisis necessary sometimes after changing the number of voxels in an
0976     % FE structure, as it is performed by feConnectomeReduceVoxels.m
0977     %
0978     % FibInRoi = feGet(fe,'uniquefibersinroi');
0979     
0980     % Get all the unique fibers in each voxel
0981     uniquefvx = fefgGet(feGet(fe,'fibers img'), ...
0982                         'uniquefibersinvox',     ...
0983                         feGet(fe,'roi coords'));
0984     val = [];
0985     for ivx = 1:length(uniquefvx)
0986         val = [val; uniquefvx{ivx}];
0987     end
0988     val = unique(val);
0989     
0990   case {'weightsinroi'}
0991     % Find the weights of the fibers in a specified volume.
0992     %
0993     % We compute the following values:
0994     % (1) The number of unique fibers in the volume
0995     % (2) The weights for the fibers in the roi
0996     %
0997     % wFibInRoi = feGet(fe,'weightsinroi');
0998     
0999     % Get all the unique fibers in each voxel
1000     FibInRoi = feGet(fe,'uniquefibersindicesinroi');
1001    
1002     % extract the fber weights obtained in a LiFE fit
1003     w   = feGet(fe,'fiber weights');
1004     
1005     % Return only the ones for the fibers in this roi
1006     val = w(unique( FibInRoi ));
1007     
1008   case {'fiberdensity'}
1009     % Fiber density statistics.
1010     %
1011     % Computes the fiber density (how many fibers in each voxel)
1012     %
1013     % We compute the following values:
1014     % (1) The number of fibers in each voxel
1015     % (2) The number of unique fibers with non-zero weights
1016     % (3) The sum of the weights in each voxel
1017     % (4) The mean of the weights in each voxel
1018     % (5) The variance of the weigths in each voxel
1019     %
1020     % pSig = feGet(fe,'fiberdensity');
1021     
1022     % Get the unique fibers in each voxel
1023     uniquefvx = fefgGet(feGet(fe,'fibers img'), ...
1024                         'uniquefibersinvox',     ...
1025                         feGet(fe,'roi coords'));
1026                       
1027     % extract the fber weights obtained in a LiFE fit
1028     w = feGet(fe,'fiber weights');
1029     
1030     % Compute the fiber density in three wasy:
1031     % (1) The number of fibers in each voxel
1032     % (2) The number of unique fibers with non-zero weights
1033     % (3) The sum of the weights in each voxel
1034     % (4) The mean of the weights in each voxel
1035     % (5) The variance of the weigths in each voxel
1036     val = nan(length(uniquefvx),5);
1037     for ivx = 1:length(uniquefvx)
1038         
1039       % Number of fibers in each voxel
1040       val(ivx,1) = length(uniquefvx{ivx});
1041       
1042       % Number of fibers in ech voxel with non-zero weight
1043       val(ivx,2) = length(uniquefvx{ivx}(w(uniquefvx{ivx}) > 0));
1044   
1045       % Sum of fiber weights in each voxel
1046       val(ivx,3) = sum(w(uniquefvx{ivx}));
1047          
1048       % Mean of fiber weights in each voxel
1049       val(ivx,4) = nanmedian(w(uniquefvx{ivx}));
1050       
1051       % Var of fibers in each voxel
1052       val(ivx,5) = nanvar(w(uniquefvx{ivx}));
1053     end
1054     
1055   case {'psigfibertest'}
1056     % Predicted signal (demeaned) with a subset of fibers' weights set to 0.
1057     % This can be used to test the loss in RMSE for the connectome when a
1058     % subset of fibers is removed, but the connectome is not fitted again.
1059     %
1060     % pSig = feGet(fe,'pSig fiber test',fiberIndices);
1061     % pSig = feGet(fe,'pSig fiber test',fiberIndices,voxelIndices);
1062     % pSig = feGet(fe,'pSig fiber test',fiberIndices,coords);
1063     if ~isempty(varargin)
1064       val = feGet(fe,'Mfiber')*feGet(fe,'fiber weights test',varargin{1});
1065           
1066       % Now select a subset of voxels if requested
1067       if (length(varargin) == 2)
1068         % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1069         % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1070         % val               = val(voxelRowsToKeep,:);
1071         val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin{2})));
1072       end
1073     else
1074       error('[%s] A set f fiber indiced must be passed in. pSig = feGet(fe,''pSig fiber test'',fiberIndices))',mfilename);
1075     end
1076     
1077   case {'psigfibertestvoxelwise'}
1078     % Predicted signal (demeaned) with a subset of fibers' weights set to 0.
1079     % This can be used to test the loss in RMSE for the connectome when a
1080     % subset of fibers is removed, but the connectome is not fitted again.
1081     %
1082     % pSig = feGet(fe,'pSig fiber test voxel wise',fiberIndices);
1083     % pSig = feGet(fe,'pSig fiber test voxel wise',fiberIndices,voxelIndices);
1084     % pSig = feGet(fe,'pSig fiber test voxel wise',fiberIndices,coords);
1085     
1086     if ~isempty(varargin)
1087       nVoxels = feGet(fe,'nvoxels');
1088       w = feGet(fe,'fiber weights test voxel wise',varargin{1}); % Weights with a subset set to 0
1089       val = cell(nVoxels,1);
1090       for ivox = 1:nVoxels        
1091         % Predict the signal.
1092         val{ivox} = feGet(fe,'Mfiber',ivox)*w(ivox,:)';
1093       end
1094       
1095      feOpenLocalCluster
1096      % Reorganize the signal into a vector
1097       val = vertcat(val{:})';
1098       
1099       % Now select a subset of voxels if requested
1100       if (length(varargin) == 2)
1101         % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1102         % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1103         % val               = val(voxelRowsToKeep,:);
1104         val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin{2})));
1105       end
1106     else
1107       error('[%s] A set f fiber indiced must be passed in. pSig = feGet(fe,''pSig fiber test'',fiberIndices))',mfilename);
1108     end
1109     
1110   case {'predictedsignalfull','psigfull'}
1111     % Predicted measured signal from both fiber and iso
1112     %
1113     % pSig = feGet(fe,'pSig full')
1114     % pSig = feGet(fe,'pSig full',coords)
1115     % pSig = feGet(fe,'pSig full',voxelIndices)
1116     val = [feGet(fe,'M fiber'), feGet(fe,'M iso')] * feGet(fe,'full weights');
1117     if ~isempty(varargin)
1118       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1119       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1120       % val           = val(voxelRowsToKeep,:);
1121       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1122     end
1123     
1124   case {'fullweights'}
1125     % The fiber and isotropic weights as a long vector
1126     %
1127     % w = feGet(fe,'fullweights')
1128     val = [feGet(fe,'fiber weights'); feGet(fe,'iso weights')];
1129   
1130   case {'fiberweightsvoxelwise'}
1131     % The woxels returned by a fit of LiFE by voxel/fiber
1132     %
1133     % w = feGet(fe,'fiberweightsvoxelwise')
1134     val = fe.life.voxfit.weights;
1135     
1136   case {'psigfvoxelwise'}
1137     % Predict the diffusion signal for the fiber component
1138     % with the voxel-wise fit of LiFE
1139     %
1140     % pSig = feGet(fe,'psigfvoxelwise')
1141     % pSig = feGet(fe,'psigfvoxelwise',coords)
1142     % pSig = feGet(fe,'psigfvoxelwise',voxelIndices)
1143     
1144     if ~isfield(fe.life,'voxfit'), 
1145       error('[%s] Cannot find voxel-wise fit.\nTo fit the model voxel-wise run:\nfe = feFitModelByVoxel(fe)\n',mfilename);
1146     end
1147     val = fe.life.voxfit.psig;
1148  
1149     % Get a subset of voxels.
1150     if ~isempty(varargin)
1151       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1152       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1153       % val           = val(voxelRowsToKeep,:);
1154       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1155     end
1156     
1157   case {'psigfvoxelwisebyvoxel'}
1158     % Predict the diffusion signal for the fiber component
1159     % with the voxel-wise fit of LiFE, return the an array of pSigXnVoxel
1160     %
1161     % pSig = feGet(fe,'psigfvoxelwisebyvoxel')
1162     % pSig = feGet(fe,'psigfvoxelwisebyvoxel',coords)
1163     % pSig = feGet(fe,'psigfvoxelwisebyvoxel',voxelIndices)
1164     nBvecs  = feGet(fe,'nBvecs');
1165     nVoxels = feGet(fe,'n voxels');
1166     val     = reshape(feGet(fe,'psigfvoxelwise'), nBvecs, nVoxels);
1167 
1168   case {'totalr2'}
1169     % Return the global R2 (fraction of variance explained) of the full life
1170     % model.
1171     %
1172     % R2 = feGet(fe,'total r2');
1173 
1174     %     measured  = feGet(fe,'dsigdemeaned');
1175     %     predicted = feGet(fe,'fiber p sig');
1176     %     val = (1 - (sum((measured - predicted).^2 ) ./ ...
1177     %                 sum((measured - mean(measured)).^2) ));
1178     val = (1 - (sum((feGet(fe,'diffusion signal demeaned') - ...
1179       feGet(fe,'fiber predicted')).^2 ) ./ ...
1180       sum((feGet(fe,'diffusion signal demeaned') - ...
1181       mean(feGet(fe,'diffusion signal demeaned'))).^2) ));
1182   
1183   case {'totalr2voxelwise'}
1184     % Return the global R2 (fraction of variance explained) of the full life
1185     % model from a voxel-wise fit.
1186     %
1187     % R2 = feGet(fe,'total r2 vocel wise');
1188 
1189     %     measured  = feGet(fe,'dsigdemeaned');
1190     %     predicted = feGet(fe,'p sig f voxel wise');
1191     %     val = (1 - (sum((measured - predicted).^2 ) ./ ...
1192     %                 sum((measured - mean(measured)).^2) ));
1193     val = (1 - (sum((feGet(fe,'diffusion signal demeaned') - ...
1194       feGet(fe,'psigfvoxelwise')').^2 ) ./ ...
1195       sum((feGet(fe,'diffusion signal demeaned') - ...
1196       mean(feGet(fe,'diffusion signal demeaned'))).^2) ));
1197    
1198   case {'totpercentvarianceexplained','totpve'}
1199     % Percent variance explained
1200     %
1201     % R2 = feGet(fe,'explained variance')
1202     val = 100 * feGet(fe,'total r2');
1203     
1204   case {'rmsetotal','totalrmse'}
1205     % Root mean squared error of the LiFE fit to the whole data
1206     %
1207     % rmse = feGet(fe,'rmse')
1208     val = sqrt(mean((feGet(fe,'diffusion signal demeaned') - ...
1209       feGet(fe,'pSig fiber')).^2));
1210   
1211   case {'totalrmsevoxelwise'}
1212     % Root mean squared error of the LiFE fit to the whole data from a
1213     % vocel-wise fit
1214     %
1215     % rmse = feGet(fe,'rmse')
1216     val = sqrt(mean((feGet(fe,'diffusion signal demeaned') - ...
1217       feGet(fe,'pSig f voxelwise')').^2));
1218   
1219   case {'ressigfiber'}
1220     % Residual signal fiber prediction - measured_demeaned.
1221     %
1222     % res = feGet(fe,'res sig fiber')
1223     val = (feGet(fe,'dsigdemeaned')    - feGet(fe,'psig fiber'));
1224     if ~isempty(varargin)
1225       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1226       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1227       % val              = val(voxelRowsToKeep,:);
1228       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1229     end
1230     
1231   case {'ressigfull'}
1232     % Residual signal full model prediction - measured signal.
1233     %
1234     % res = feGet(fe,'res sig full');
1235     % res = feGet(fe, 'res sig full',coords);
1236     % res = feGet(fe, 'res sig full',voxelIndex);
1237     val = (feGet(fe,'dsig full')    - feGet(fe,'psig full')');
1238     if ~isempty(varargin)
1239       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1240       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1241       % val           = val(voxelRowsToKeep,:);
1242       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1243     end
1244     
1245   case {'ressigfullvoxelwise'}
1246     % Residual signal full model prediction from a multi-voxel fit.
1247     %
1248     % res = feGet(fe,'res sig full voxfit');
1249     % res = feGet(fe, 'res sig full voxfit',coords);
1250     % res = feGet(fe, 'res sig full voxfit',voxelIndex);
1251     %tic,val      = feGet(fe,'dsig demeaned') - feGet(fe,'psigfvoxelwise') + feGet(fe,'dsigiso');toc
1252     val      = feGet(fe,'dsig full') - feGet(fe,'psigfvoxelwise')';
1253     if ~isempty(varargin)
1254       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1255       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1256       % val           = val(voxelRowsToKeep,:);
1257       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1258     end
1259     
1260   case {'fiberressigwithmean'}
1261     % Residual signal fiber model prediction - demeaned measured signal
1262     % with added mean signal. VECTOR FORM.
1263     %
1264     % This is used to reconstruct an image (volume) to be used for the
1265     % refinement process.
1266     %
1267     % res = feGet(fe,'fiber res sig with mean');
1268     
1269     % predicted = feGet(fe,'psig fiber');
1270     % measured  = feGet(fe,'dsigdemeaned');
1271     % val = (measured_full - predicted demeaned);
1272     val = (feGet(fe,'dsig full')' - feGet(fe,'psig fiber')); 
1273     
1274     if ~isempty(varargin)
1275       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1276       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1277       % val           = val(voxelRowsToKeep,:);
1278       val = val(feGet(fe,'voxel rows',feGet(fe,'voxelsindices',varargin)));
1279     end
1280     
1281   case {'predictedfibersignalvoxel','psigfvox'}
1282     % Predicted signal by the fiber model in a set of voxels.
1283     %
1284     % Vox subfield stores per voxel within the VOI
1285     % The pSig has size of the dwi.
1286     % It is stored as val = pSig(X,Y,Z,Theta)
1287     %
1288     % pSig = feGet(fe, 'pSig fiber by voxel');
1289     % pSig = feGet(fe, 'pSig fiber by voxel',coords);
1290     % pSig = feGet(fe, 'pSig fiber by voxel',voxelIndex);
1291     nBvecs  = feGet(fe,'nBvecs');
1292     nVoxels = feGet(fe,'n voxels');
1293     val     = reshape(feGet(fe,'pSig fiber'), nBvecs, nVoxels);
1294     val     = val(:,feGet(fe,'return voxel indices',varargin));
1295     
1296   case {'predictedfullsignalvoxel','psigfullvox'}
1297     % Predicted signal by the full model in a set of voxeles.
1298     %
1299     % Vox subfield stores per voxel within the VOI
1300     % The pSig has size of the dwi.
1301     % It is stored as val = pSig(X,Y,Z,Theta)
1302     %
1303     % pSig = feGet(fe, 'pSig full by voxel');
1304     % pSig = feGet(fe, 'pSig full by voxel',coords);
1305     % pSig = feGet(fe, 'pSig full by voxel',voxelIndex);
1306     nBvecs  = feGet(fe,'nBvecs');
1307     nVoxels = feGet(fe,'n voxels');
1308     val     = reshape(feGet(fe,'pSig full'), nBvecs, nVoxels);
1309       
1310   case {'voxelr2','r2vox','voxr2','r2byvoxel'}
1311     % Return a column vector of the proportion of variance explained in
1312     % each voxel.
1313     %
1314     % R2byVox = feGet(fe,'voxr2');
1315     % R2byVox = feGet(fe,'voxr2',coords);
1316     measured  = feGet(fe,'dSig demeaned by voxel');
1317     predicted = feGet(fe,'pSig f vox');
1318     nBvecs    = feGet(fe,'nBvecs');
1319     val       = (1 - (sum((measured - predicted).^2 ) ./ ...
1320       sum((measured - repmat(mean(measured), nBvecs,1)).^2 ) ));
1321     val       = val(feGet(fe,'return voxel indices',varargin));
1322   
1323   case {'voxelr2zero','r2voxzero','voxr2zero','r2byvoxelzero'}
1324     % Return a column vector of the proportion of variance explained in
1325     % each voxel. (Normalized to the squared diffusion signal in each voxel)
1326     %
1327     % R2byVox = feGet(fe,'voxr2zero');
1328     % R2byVox = feGet(fe,'voxr2zero',coords);
1329     measured  = feGet(fe,'dSig demeaned by voxel');
1330     predicted = feGet(fe,'pSig f vox');
1331     val       = (1 - (sum((measured - predicted).^2 ) ./ sum(measured.^2)));
1332     val       = val(feGet(fe,'return voxel indices',varargin));
1333    
1334   case {'voxelvarianceexplained','varexpvox','voxvarexp','varexpbyvoxel'}
1335     % Return the percent of varince explained in each voxel.
1336     %
1337     % R2byVox = feGet(fe,'var exp by voxel');
1338     % R2byVox = feGet(fe,'var exp by voxel',coords);
1339     val = 100.*feGet(fe,'voxr2');
1340     val = val(feGet(fe,'return voxel indices',varargin));
1341     
1342   case {'voxelr2voxelwise','r2voxvoxelwise','voxr2voxelwise'}
1343     % Return a column vector of the proportion of variance explained in
1344     % each voxel.
1345     %
1346     % R2byVox = feGet(fe,'voxr2voxelwise');
1347     % R2byVox = feGet(fe,'voxr2voxewise',coords);
1348     measured  = feGet(fe,'dSig demeaned by voxel');
1349     predicted = feGet(fe,'psig f voxel wise by voxel');
1350     nBvecs    = feGet(fe,'nBvecs');
1351     val       = (1 - (sum((measured - predicted).^2 ) ./ ...
1352       sum((measured - repmat(mean(measured), nBvecs,1)).^2 ) ));
1353     val       = val(feGet(fe,'return voxel indices',varargin));
1354   
1355   case {'voxelr2zerovoxelwise','voxr2zerovoxelwise'}
1356     % Return a column vector of the proportion of variance explained in
1357     % each voxel. (Normalized to the squared diffusion signal in each voxel)
1358     %
1359     % R2byVox = feGet(fe,'voxr2zerovoxelwise');
1360     % R2byVox = feGet(fe,'voxr2zerovoxelwise',coords);
1361     measured  = feGet(fe,'dSig demeaned by voxel');
1362     predicted = feGet(fe,'psig f voxel wise by voxel');
1363     val       = (1 - (sum((measured - predicted).^2 ) ./ sum(measured.^2)));
1364     val       = val(feGet(fe,'return voxel indices',varargin));
1365    
1366   case {'voxelvarianceexplainedvoxelwise','varexpvoxvoxelwise'}
1367     % Return the percent of varince explained in each voxel.
1368     %
1369     % R2byVox = feGet(fe,'var exp by voxel');
1370     % R2byVox = feGet(fe,'var exp by voxel',coords);
1371     val = 100.*feGet(fe,'voxr2voxelwise');
1372     val = val(feGet(fe,'return voxel indices',varargin));
1373     
1374   case {'dsigdemeanedbyvoxel','dsigdemeanedvox'}
1375     % Demeaned diffusion signal in each voxel
1376     %
1377     % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel');
1378     % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',coords);
1379     % dSigByVoxel = feGet(fe,'dsigdemeaned by Voxel',vxIndex);
1380     nBvecs  = feGet(fe,'nBvecs');
1381     nVoxels = feGet(fe,'n voxels');
1382     val     = reshape(feGet(fe,'dsigdemeaned'), nBvecs, nVoxels);
1383     val     = val(:,feGet(fe,'return voxel indices',varargin));
1384     
1385   case {'dsigfullbyvoxel','dsigfullvox','voxdsigfull'}
1386     % Full (measured) signal in each voxel
1387     %
1388     % dSigByVoxel = feGet(fe,'dSig full by Voxel');
1389     % dSigByVoxel = feGet(fe,'dSig full by Voxel',coords);
1390     % dSigByVoxel = feGet(fe,'dSig full by Voxel',vxIndex);
1391     nBvecs  = feGet(fe,'nBvecs');
1392     nVoxels = feGet(fe,'n voxels');
1393     val     = reshape(feGet(fe,'dSig full'), nBvecs, nVoxels);
1394     val    = val(:,feGet(fe,'return voxel indices',varargin))';
1395     
1396   case {'voxelrmse','voxrmse'}
1397     % A volume of RMSE values
1398     %
1399     % RMSE = feGet(fe,'vox rmse')
1400     % RMSE = feGet(fe,'vox rmse',coords)
1401     % RMSE = feGet(fe,'vox rmse',vxIndex)
1402     measured  = feGet(fe,'dsigdemeaned by voxel');
1403     predicted = feGet(fe,'pSig f vox');
1404     val       = sqrt(mean((measured - predicted).^2,1));
1405     val       = val(feGet(fe,'voxelsindices',varargin));
1406    
1407   case {'voxelrmsevoxelwise','voxrmsevoxelwise'}
1408     % A volume of RMSE values optained with the voxel-wise (voxelwise) fit.
1409     %
1410     % RMSE = feGet(fe,'vox rmse voxelwise')
1411     % RMSE = feGet(fe,'vox rmse voxelwise',coords)
1412     % RMSE = feGet(fe,'vox rmse voxelwise',vxIndex)
1413     measured  = feGet(fe,'dsigdemeaned by voxel');
1414     predicted = feGet(fe,'pSig f voxel wise by voxel');
1415    
1416     val       = sqrt(mean((measured - predicted).^2,1));
1417     val       = val(feGet(fe,'voxelsindices',varargin));
1418 
1419   case {'voxelrmsetest','voxrmsetest'}
1420     % A volume of RMSE values with a subset of fibers' weights set to 0.
1421     %
1422     % RMSE = feGet(fe,'vox rmse',fiberIndices)
1423     % RMSE = feGet(fe,'vox rmse',fiberIndices,coords)
1424     % RMSE = feGet(fe,'vox rmse',fiberIndices,voxelIndex)
1425     measured  = feGet(fe,'dsigdemeaned by voxel');
1426     % Reshape the predicted signal by voxles
1427     predicted = reshape(feGet(fe,'pSig fiber test',varargin{1}), feGet(fe,'nBvecs'), feGet(fe,'nVoxels'));   
1428     val       = sqrt(mean((measured - predicted).^2,1));
1429     
1430     if length(varargin) == 2
1431       val       = val(feGet(fe,'voxelsindices',varargin));
1432     end
1433     
1434   case {'residualsignalfibervoxel','resfibervox'}
1435     % Fibers' residual signal by voxel
1436     %
1437     % res = feGet(fe,'res sig fiber vox')
1438     % res = feGet(fe,'res sig fiber vox',coords)
1439     % res = feGet(fe,'res sig fiber vox',vxIndex)
1440     nBvecs  = feGet(fe,'nBvecs');
1441     nVoxels = feGet(fe,'n voxels');
1442     val     = reshape(feGet(fe,'res sig fiber'), nBvecs, nVoxels);
1443     val     = val(:,feGet(fe,'return voxel indices',varargin))';
1444     
1445   case {'residualsignalfullvoxel','resfullvox'}
1446     % Full (measured) residual signal by voxel
1447     %
1448     % res = feGet(fe,'res sig full vox')
1449     % res = feGet(fe,'res sig full vox',coords)
1450     % res = feGet(fe,'res sig full vox',vxIndex)
1451     nBvecs  = feGet(fe,'nBvecs');
1452     nVoxels = feGet(fe,'n voxels');
1453     val     = reshape(feGet(fe,'res sig full'), nBvecs, nVoxels);
1454     val     = val(:,feGet(fe,'return voxel indices',varargin))';
1455       
1456   case {'fiberressigwithmeanvoxel'}
1457     % Residual signal fiber model prediction - demeaned measured signal
1458     % with added mean signal. VOXEL FORM (nBvecs x nVoxel).
1459     %
1460     % This is used to reconstruct an image (volume) to be used for the
1461     % refinement process.
1462     %
1463     % res = feGet(fe,'fiber res sig with mean');
1464     
1465     % predicted = feGet(fe,'psig fiber');
1466     % measured  = feGet(fe,'dsigdemeaned');
1467     % val = (measured     - predicted) + (measured_full - measured);
1468     val     = feGet(fe,'fiberressigwithmean');
1469     nBvecs  = feGet(fe,'nBvecs');
1470     nVoxels = feGet(fe,'n voxels');
1471     val     = reshape(val, nBvecs, nVoxels);
1472     
1473     if ~isempty(varargin)
1474       % voxelIndices     = feGet(fe,'voxelsindices',varargin);
1475       % voxelRowsToKeep  = feGet(fe,'voxel rows',voxelIndices);
1476       % val              = val(voxelRowsToKeep,:);
1477       val = val(:, feGet(fe,'return voxel indices',varargin));
1478     end
1479     
1480   case {'fiberressigwithmeanvox','resfibermeanvox'}
1481     % Fibers' residual signal by voxel with mean signal added (with added
1482     % isotropic component).
1483     %
1484     % This is used to compute the residual signal for the refinement.
1485     %
1486     % res = feGet(fe,'fiber res sig with mean vox')
1487     % res = feGet(fe,'fiber res sig with mean vox',coords)
1488     % res = feGet(fe,'fiber res sig with mean vox',vxIndex)
1489     nBvecs  = feGet(fe,'nBvecs');
1490     nVoxels = feGet(fe,'n voxels');
1491     val     = reshape(feGet(fe,'fiber res sig with mean'), nBvecs, nVoxels);
1492     val     = val(:,feGet(fe,'return voxel indices',varargin))';
1493     
1494   case {'voxelsindices','returnvoxelindices','voxelindexes''returnvoxelindexes'}
1495     % Given an VOI or a set of indices to voxels returns the indices of the matching voxels inside the big
1496     % volume, which ordinarily represents the full connectome.
1497     %
1498     % voxelIndices = feGet(fe,'voxelsindices',coords)
1499     % voxelIndices = feGet(fe,'voxelsindices',voxelIndices)
1500     %                IMPORTANT: Indices MUST be a column vector for this
1501     %                code to work.
1502     %
1503     % coords is a Nx3 set of coordinates in image space
1504     % voxelIndices is a vector of 1's and 0's, there is a one for each
1505     % location the the connectome coordinates for which there is a match in
1506     % the coords
1507     %
1508     varargin = varargin{1};
1509     if ( ~isempty(varargin) )
1510       if ( size(varargin{1},2) == 3 )
1511         % If a set of coordinates were passed in we return the indices.
1512         val = logical(feGet(fe,'find voxels',varargin{1}));
1513       else
1514         % If indices were passed in, we sort and return them.
1515         val = sort(varargin{1});
1516       end
1517     else
1518       % If no coordinates were passed at all, we return all the indices.
1519       val = true(feGet(fe,'n voxels'),1);
1520     end
1521     
1522   case {'findvoxels','findvoxelindexes','findvoxelsinconnectome','findvoxelsinconnectomeroi', ...
1523       'voxel2index','coords2index'}
1524     % Given an VOI finds the indices of the matching voxels inside the big
1525     % volume, which ordinarily represents the full connectome.
1526     %
1527     % foundVoxels = feGet(fe,'find voxels',coords)
1528     %
1529     % coords is a Nx3 set of coordinates in image space
1530     % foundVoxels is a vector of 1's and 0's, there is a one for each
1531     % location the the connectome coordinates for which there is a match in
1532     % the coords
1533     
1534     % Compute the values for a subset of voxels
1535     if isempty(varargin)
1536       % If no coordinates were passed at all, we return all the indices.
1537       val = ones(feGet(fe,'n voxels'),1);
1538     else
1539       % The stored coordinates are at a resolution of the image, typically
1540       % 2mm isotropic.  The VOI should also be in image resolution.
1541       % ---- Franco:
1542       % This is how I had it. I think it is worng:
1543       % val = ismember(feGet(fe,'roi coords'), varargin{1}, 'rows'); % This is slow
1544       % This is hwo I think it should be:
1545       [~,val] = ismember(varargin{1}, feGet(fe,'roi coords'),'rows'); % This is slow
1546     end
1547     
1548   case {'voxelcoords2voxelrows','coords2rows'}
1549     % Given a set of VOI coords finds the row numbers of the Model matrix
1550     % (or equivalently the dSig vector) that represent the data for this
1551     % set of VOI coords.
1552     %
1553     % foundVoxels = feGet(fe,'coords 2 rows',coords)
1554     %
1555     % coords      - a Nx3 set of coordinates in image space
1556     % foundVoxels - a binary vector that is 1 for each Model matrix row
1557     %               that corresponds to at least one of the coords.
1558     val = feGet(fe,'voxel rows',find(feGet(fe,'find voxels',varargin{1})));
1559     
1560     % ------ Spatial coordinate transforms for voxels and fg to coordinate frames
1561   case {'xformimg2acpc','xform2acpc','img2acpc','img2acpcxform'}
1562     % Quaternian transformation from IMAGE space to ACPC space.
1563     %
1564     % xform = feGet(fe,'xform')
1565     val = fe.life.xform.img2acpc;
1566   case {'xformacpc2img','xform2img','acpc2img','acpc2imgxform'}
1567     % Quaternian transformation from ACPC space to IMAGE space.
1568     %
1569     % xform = feGet(fe,'xform')
1570     val = fe.life.xform.acpc2img;
1571   case {'volumesize','dims','dim','imagedim'}
1572     % Dimensions of the DW volume.
1573     %
1574     % dim = feGet(fe,'dims')
1575     val = fe.life.imagedim;
1576   case {'mapsize'}
1577     % Dimensions of the maps of parameters and results.
1578     %
1579     % dims = feGet(fe, 'mapsize')
1580     val = fe.life.imagedim(1:3);
1581     
1582   case {'anatomyfile'}
1583     % Path to the 3D Anatomy Volume.
1584     % anatomyfile = feGet(fe, 'anatomy file')
1585     val = fe.path.anatomy;
1586   case 'dtfile'
1587     % Diffusion weighted file used for testing results
1588     % dtfile = feGet(fe,'dtfile')
1589      val = fe.path.dtfile;  
1590 
1591   otherwise
1592     help('feGet')
1593     fprintf('[feGet] Unknown parameter << %s >>...\n',param);
1594     keyboard
1595 end
1596 
1597 end % END MAIN FUNCTION

Generated on Wed 16-Jul-2014 19:56:13 by m2html © 2005