orientation error in 3dmaskdump to 3dUndump pipeline

I am working on a searchlight analysis and am using 3dmaskdump and 3dUndump in MATLAB. However, after running the searchlight, the results seem to be flipped in orientation – even though the 3dinfo -verb output says all data are in LPI.

For example, I get a series out errors like this:


e[7m*+ WARNING:e[0m File /Users/andrewlynn/Desktop/sf_afni_tmp/test.txt line 452016: y coord=-92.5 is outside -91.2525 .. 126.253

Below I simplified this by trying to pull the atlas info then use 3dUndump to recreate the atlas and the flip happens here too.

I think there may be a bug in the AFNI code? This seems to be fixed by multiplying the X and Y coords



cmask = ['/Volumes/NBL_Projects/NSF_DDK2/matfiles/preprocessing_pipeline/HaskinsPeds/HaskinsPeds_NL_atlas2.5+tlrc.BRIK.gz'];

loc = ['~/Desktop/sf_afni_tmp'];

unix(['3dmaskdump -overwrite -noijk -xyz -o ' loc 'tmp.n_voxel_coord '  cmask]);

rois = dir([loc 'tmp.n_voxel_coord']);
nrois = load([rois.folder '/' rois.name]);

writematrix(nrois,[loc '/test.txt'],'Delimiter','tab');

unix(['3dUndump -overwrite -xyz -datum float -prefix ' loc '/Haskings_coord_mask -master ' cmask ' ' loc '/test.txt']);


3dmaskdump always writes xyz coordinates in RAI order. 3dUndump always reads in coordinates in the master dataset’s storage orientation. You can work around this by creating a dataset in RAI storage orientation with “3dresample -orient RAI” or by using the ijk output instead from 3dmaskdump and the -ijk input for 3dUndump.

Thank so much!