help > MATLAB and MRIcron flipped images
Showing 1-2 of 2 posts
Display:
Results per page:
Sep 11, 2018  07:09 PM | sjack
MATLAB and MRIcron flipped images
Hello,

I am having issues viewing scans in MATLAB vs MRIcron. I view images in MATLAB using the loadimage('scan.img') and I use the scan.hdr to view in MRIcron. The issue is that for some images, MRIcron will display the flipped version (ie the right half of the brain is now the left, and the left half of the brain is now the right). In MATLAB, the function interp3 will interpolate the image but also flip its orientation only in MRIcron and not MATLAB. This is the same for some other functions as well. As you can imagine, it is very frustrating to process images without seeing the correct orientation in MRIcron. This is also very problematic for drawing ROIs, as these may be drawn on the incorrect side. I am still getting used to MATLAB and MRIcron so I really do not know why this is the case. My only thought it that the .hdr file could contain different data than the .img file.

To sum up: Does anyone know why MRIcron is showing a flipped image as compared to in MATLAB? If so, how can I get it to read it correctly?

Thanks!
Sep 12, 2018  12:09 PM | Chris Rorden
RE: MATLAB and MRIcron flipped images
MRIcron is able to use the spatial rotation transform to re-orient images for consistent display. Use the Help/Preferences to decide if you want to view the raw data (rows, columns and slices as saved on disk, regardless of spatial orientation), rotated to nearest orthogonal, or resliced. 

If you want consistent spatial display in Matlab you will need to take the spatial transforms (S/Q Forms) into account. 

My personal favorite solution is Xiangrui Li's nii_viewer and nii_tool. This includes simple functions for reorienting data
  nii_viewer('nifti.nii')

Other solutions include

Matlab 2018: (see hdr.Transform.T)
hdr = niftiinfo('nifti.nii');
img = niftiread('nifti.nii');

SPM: (see hdr.mat)
hdr = spm_vol('nifti.nii');
img = spm_read_vols(hdr);

Jimmy Shen's Matlab tools.

Be aware that the NIfTI S-Form is indexed from zero (since the first element in a C array is v[0]), whereas the transforms shown by some of the tools above adjust this to be indexed from one (singe the first element in a Matlab array is v[1]). You need to keep this in mind when determining coordinates and saving NIfTI files.