Skip to content

Commit

Permalink
added a flipdim for dimension 2 in the migration tool. This was neede…
Browse files Browse the repository at this point in the history
…d because at some point our preferred orienation for display purposes switched from ARS to PRS. This made no difference for data sets initialized with new code, but it did matter for data sets migrated from old vista formats
  • Loading branch information
JWinawer committed Jun 22, 2014
1 parent b976c4c commit d9b0167
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
31 changes: 30 additions & 1 deletion fileFilters/nifti/niftiCreateXform.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
function [xform] = niftiCreateXform(nii,xformType)
%First create a specified transform onto the supplied nifti struct.
%Create a specified transform onto the supplied nifti struct. For
% data in slice format, we specify our output data xform according to
% certain rules. Our preferred orientation is PRS, but we do not want to
% change the slice dimension, so we apply these rules:
%
% 1. The slice dimension is third
% 2. The slice dimension does not change direction or axis
% 3. Except for the slice dimension, we remap any of LIA => RSP
% 4. If slice dimension is not L or R, then 2nd dimension is R
% 5. If slice dimension is not A or P, then 1st dimension is P
%
% For example,
%
% xformIn = [...
% 'ASR' ; 'AIR' ; 'PSR' ; 'PIR' ; 'SAR' ; 'SPR' ; 'IAR' ; 'IPR' ;
% 'ASL' ; 'AIL' ; 'PSL' ; 'PIL' ; 'SAL' ; 'SPL' ; 'IAL' ; 'IPL' ;
% 'ARS' ; 'ALS' ; 'PRS' ; 'PLS' ; 'RAS' ; 'RPS' ; 'LAS' ; 'LPS' ;
% 'ARI' ; 'ALI' ; 'PRI' ; 'PLI' ; 'RAI' ; 'RPI' ; 'LAI' ; 'LPI' ;
% 'SRA' ; 'SLA' ; 'IRA' ; 'ILA' ; 'RSA' ; 'RIA' ; 'LSA' ; 'LIA' ;
% 'SRP' ; 'SLP' ; 'IRP' ; 'ILP' ; 'RSP' ; 'RIP' ; 'LSP' ; 'LIP' ;
% ];
%
% xformOut = xformIn;
% for ii = 1:length(xformIn)
% xformOut(ii,:) = niftiCreateStringInplane(xformIn(ii,:),3);
% fprintf('%s=>%s\n',xformIn(ii,:), xformOut(ii,:));
% end

% See niftiCreateStringInplane for the computation.
%
% USAGE
% nii = readNifti(niftiFullPath);
Expand All @@ -13,6 +41,7 @@
% RETURNS
% Xform matrix in the form a quaternion
%
% See also niftiCreateStringInplane
%
% Copyright Stanford VistaLab 2013

Expand Down
17 changes: 16 additions & 1 deletion mrBOLD/Init/mrInit_updateInplaneSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,23 @@ function mrInit_updateInplaneSession()
inplanePath = fullfile(pwd,'Inplane', 'anat.mat');

inplaneAnat = load(inplanePath);
inplaneAnat.anat = permute(inplaneAnat.anat,[2 1 3]);

% The following transform will preserve the orientation of the data
% across the migration, such that inplane to vAnatomy xforms do not
% need to change, nor do parameter maps, ROIs, etc. The permute([2 1])
% followed by flipdim(2) effectively converts from x/y coordinates to
% row/column coordinates. The reason we do this is that the old
% vistasoft (prior to the move to NIFTIs) did this transform when
% showing the slices as images, whereas the current code simply pulls
% the data array from a nifti (after applying a standard xform to the
% nifti), and uses an image tool such as imagesc slice by slice without
% re-orienting the array. Since we no longer do this xform each time we
% show the data, we must do it here as part of the migration if want
% the migrated data to appear the same way as the pre-migrated data.
% See also mrInit_updateSessiontSeries.m.
inplaneAnat.anat = permute(inplaneAnat.anat,[2 1 3]);
inplaneAnat.anat = flipdim(inplaneAnat.anat,2);

%Build the transform
mrSESSION.inplanes.voxelSize = mrSESSION.inplanes.voxelSize([2 1 3]);
xform = [diag(1./mrSESSION.inplanes.voxelSize), size(inplaneAnat.anat)'/2; 0 0 0 1];
Expand Down
15 changes: 15 additions & 0 deletions mrBOLD/Init/mrInit_updateSessiontSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,22 @@ function mrInit_updateSessiontSeries()
tSeriesIn = reshape(tSeriesIn.tSeries, dimSize(1:3));
tSeries(:,:,:,slice) = tSeriesIn;
end %for

% The following transform will preserve the orientation of the data
% across the migration, such that inplane to vAnatomy xforms do not
% need to change, nor do parameter maps, ROIs, etc. The permute([2 1])
% followed by flipdim(2) effectively converts from x/y coordinates to
% row/column coordinates. The reason we do this is that the old
% vistasoft (prior to the move to NIFTIs) did this transform when
% showing the slices as images, whereas the current code simply pulls
% the data array from a nifti (after applying a standard xform to the
% nifti), and uses an image tool such as imagesc slice by slice without
% re-orienting the array. Since we no longer do this xform each time we
% show the data, we must do it here as part of the migration if want
% the migrated data to appear the same way as the pre-migrated data.
% See also mrInit_updateInplaneSession.m.
tSeries = permute(tSeries,[3 2 4 1]); %Standard format: freq phase slice time
tSeries = flipdim(tSeries, 2);
%Note: this needed to be changed to reflect the fact that
%MATLAB stores values row, column, etc. and not column,
%row,
Expand Down

0 comments on commit d9b0167

Please sign in to comment.