MATLAB Answers

niftiwrite changes the axis of 3D images

20 views (last 30 days)
banikr on 25 Aug 2019
Commented: falkon on 30 Jul 2021
After performing some image processing in a 3D .nii format nifti image, I am using niftiwrite function to save it. But the nifti image is being saved in opposite axis like the anterior axis is being saved as posterior and vice versa, and the left to right ...
I am using itk-snap to visualize the saved image.
falkon on 30 Jul 2021
I have Matlab 2020b, and the bug is still not fixed.
The Matlab flips the signs of the quatern_b, quatern_c and quatern_d values in the raw nifty metadata.
orig_info = niftiinfo(load_from_path)
orig_data = niftiread(load_from_path)
niftiwrite(orig_data, save_to_path, orig_info, 'Compressed', true)
tmp_info = niftiinfo(save_to_path)
% Compare these two:
A "funny" work-around is to re-save the nifty (i.e., load the new created file and re-save it again) -- so the signs will be flipped back to the expected values.
It would be very nice from Matlab developers to fix this stupid bug... :-\

Sign in to comment.

Answers (1)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by