fslmaths z value behavior
neurolabusc opened this issue · comments
This demo exhibits that fslmaths -ztop
and -ptoz
show unexpected behavior. The round trip ends up converting extreme z scores to zero, rather than clamping them. niimath performs nicely for positive values, but extreme negatives become more extreme (as we get to the subnormal range we need to ensure we choose a value that further away from zero).
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#Test FSLmaths commands
# -ztop : Convert Z-stat to (uncorrected) P
# -ptoz : Convert (uncorrected) P to Z
# test image is -12,-11...+12
#
#fslmaths f32_zval -ztop -ptoz fsl32_zval
#niimath f32_zval -ztop -ptoz n32_zval
#fslmaths -dt double f64_zval -ztop -ptoz fsl64_zval -odt double
#niimath -dt double f64_zval -ztop -ptoz n64_zval -odt double
#
#fslmaths float64 results in 0 when z > 8 or z < -8
#fslmaths float32 results in 0 when z > 8 or z < -5
import nibabel as nib
import numpy as np
def makenii():
data = np.arange(5*5).reshape(5,5,1)
mid = np.rint(0.5 * (np.amax(data) + 1))
data = np.subtract(data, mid)
data32 = data.astype('float32')
img32 = nib.Nifti1Image(data32, affine=np.eye(4))
nib.save(img32, 'f32_zval.nii')
data64 = data.astype('float64')
img64 = nib.Nifti1Image(data64, affine=np.eye(4))
nib.save(img64, 'f64_zval.nii')
if __name__ == '__main__':
makenii()
Latest niimath commit has -ztop
clamp input voxels to -5.41 (or -8.29 if -dt double
). It will also emit a warning if any converted voxels required clamping:
ztop clamped 7 extremely negative z-scores
Latest niimath commit has -ztop
clamp input voxels to 13.0 regardless of datatype. Will emit clamp warning for both extreme negative and positive input values.
Latest commit ensures niimath clamps values. Issue has been reported to fsl developers (@hanayik)