diff --git a/fsl/scripts/resample_image.py b/fsl/scripts/resample_image.py index 81b329ce4b144cd2cd1788c73e117f8227bc600d..b2ef4b9c079b5b01a0bf9df298e11633b5508edf 100644 --- a/fsl/scripts/resample_image.py +++ b/fsl/scripts/resample_image.py @@ -196,6 +196,19 @@ def main(argv=None): xform = None resampled = fslimage.Image(resampled, xform=xform, header=hdr) + + # Adjust the pixdims of the + # higher dimensions if they + # have been resampled + if len(resampled.shape) > 3: + + oldPixdim = args.input.pixdim[3:] + oldShape = args.input.shape[ 3:] + newShape = resampled .shape[ 3:] + + for i, (p, o, n) in enumerate(zip(oldPixdim, oldShape, newShape), 4): + resampled.header['pixdim'][i] = p * o / n + resampled.save(args.output) return 0 diff --git a/fsl/utils/image/resample.py b/fsl/utils/image/resample.py index 0047444b4c34e856d6548972f704fa1569b51a50..91e79e6c0416cc01187bc4c636f59ec56aa23668 100644 --- a/fsl/utils/image/resample.py +++ b/fsl/utils/image/resample.py @@ -210,7 +210,12 @@ def resample(image, # might not return a 4x4 matrix, so we # make sure it is valid. if matrix.shape != (4, 4): - matrix = np.vstack((matrix[:3, :4], [0, 0, 0, 1])) + rotmat = matrix[:3, :3] + offsets = matrix[:3, -1] + matrix = np.eye(4) + matrix[:3, :3] = rotmat + matrix[:3, -1] = offsets + matrix = transform.concat(image.voxToWorldMat, matrix) return data, matrix