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.