-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility for complex vox2ras matrices (#33)
The previous implementation assumed a single term per column in the vox2ras matrix of the segmentationFile NIfTI. However, if a vox2ras matrix with multiple terms was used, CATO would throw an error. This update adds compatibility for such complex vox2ras matrices. Additionally, the tests have been updated to include these complex vox2ras matrices (with mri_info as reference).
- Loading branch information
1 parent
f7a54e2
commit 41a3ae5
Showing
3 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
function orientationStr = nifti_orientation(vox2ras) | ||
% NIFTI_ORIENTATION computes the orientation string from the vox2ras | ||
% matrix. | ||
% | ||
% Input: | ||
% vox2ras: a 4x4 matrix (typically the vox2ras parameter from the | ||
% NIFTI file header). | ||
% | ||
% Output: | ||
% orientation_str: a string indicating the orientation (e.g. 'RAS' or | ||
% 'LPI'). | ||
|
||
% Notes: | ||
% For more information on the vox2ras transformation see the FreeSurfer | ||
% documentation: | ||
% https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems | ||
|
||
% Extract the direction cosine matrix (3x3) | ||
R = vox2ras(1:3, 1:3); | ||
|
||
% Compute the orientation codes | ||
orientationCode = zeros(1, 3); | ||
for i = 1:3 | ||
[~, maxIndx] = max(abs(R(:,i))); | ||
if R(maxIndx, i) > 0 | ||
orientationCode(i) = maxIndx; | ||
else | ||
orientationCode(i) = -maxIndx; | ||
end | ||
end | ||
|
||
% Convert orientation codes to orientation string | ||
orientationStr = '???'; | ||
for i = 1:3 | ||
switch orientationCode(i) | ||
case 1 | ||
orientationStr(i) = 'R'; | ||
case -1 | ||
orientationStr(i) = 'L'; | ||
case 2 | ||
orientationStr(i) = 'A'; | ||
case -2 | ||
orientationStr(i) = 'P'; | ||
case 3 | ||
orientationStr(i) = 'S'; | ||
case -3 | ||
orientationStr(i) = 'I'; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters