I have a nifti file with all negative values and 0. I want to find the highest negative value (so 0 excluded) and I used the following command:
3dBrickStat -max -slow -non-zero mynifti.nii.gz
It gives me the correct value.
Then I want to check how many voxels have that value and I use this command:
3dBrickStat -count -non-zero “mynifti.nii.gz<$max_value…1>”
While in some cases it gives me the correct value, in other cases it returns 0, which does not make sense to me because if the -max option says that the max value is $max_value, then there should be at least 1 voxel with that value.
Thank you very much,
Are these floating point values? Looking for equality therein might have precision issues, esp. if they values are very high precision so even printing out that value could have rounding issues.
I would be tempted to first use 3dcalc before counting:
-a DSET \
-expr "within(a,MAXVAL,0)" \
… and then simply count the ones in DSET_MASK.
Thank you for your response.
Yes, these are floating point values.
If I use 3dcalc as you wrote it, then all my 0s will become 1, so I substituted the 0 in “within(a,MAXVAL,0)” with a negative number close to 0 and bigger than MAXVAL.
Still when I do count the ones in DSET_MASK I got 0 voxels.
I tried 3dBrickStat -count -non-zero “mynifti.nii.gz<$max_value…1>” with $max_value being a value slightly smaller than $max_value, and it worked. So it is likely a rounding issue as you said.
I guess I will need to manually round down the $max_value.
Thank you for your help!
Uh, right, I should have thought about the zeros aspect. But for your negative-only data, you can:
-a DSET \
-expr "within(a,MAXVAL,0)*bool(a)" \
… so that the values with exactly 0 are excluded.