Load nii volumes from 3d Slicer to Matlab

Anatole
Sat, 27 May 2023 03:44:57 +0000
Support

Operating system: Windows 10
Slicer version: 3D Slicer 5.2.2.2
Expected behavior: Get the same volumes with the same absolute position in world coordinates from 3d Slicer in Matlab
Actual behavior: Get a slight position difference in world coordinates from 3d Slicer in Matlab

I loaded 2 nifti volumes on 3d Slicer and on Matlab. I tried to get the same world coordinates in Matlab as 3dSlicer.
When visualising volume 1 and volume 2 in world coordinates with matlab I have a slight diffrence in positions.
How to load in world coordinates nii volumes on Maltab ?

Code used below
Code :
% Referential where data are loaded
Rref = imref3d([800 800 400],[-200 200],[-200 200],[-100 100]);

% Load volume 1 from 3d Slicer in Referential Rref
Vol1=niftiread(fixedpath);
Vol1=permute(Vol1,[2 1 3]);
info=niftiinfo(niipath);
tformload=affine3d(info.Transform.T);
Vol1=imwarp(Vol1,imref3d(size(Vol1)),tformload,‘nearest’,‘FillValues’,min(Vol1(:)),‘OutputView’,Rref);

% Load volume 2 from 3d Slicer in Referential Rref
Vol2=niftiread(movingpath);
Vol2=permute(Vol2,[2 1 3]);
info=niftiinfo(niipath);
tformload=affine3d(info.Transform.T);
Vol2=imwarp(Vol2,imref3d(size(Vol2)),tformload,‘nearest’,‘FillValues’,min(Vol2(:)),‘OutputView’,Rref);

Volumes on Slicer

Volumes on Matlab

2 posts - 2 participants