关于nifti文件的int16和float32数据类型的问题

有时候用 spm12的Display选项打开nifti之后发现nifti数据文件的数据类型是不一样的,比如int16和float32,会心生疑惑,两种数据类型对数据分析有影响吗?
事实上,nifti文件的大小就但等于dimensions乘以数据类型的长度,比如下图中数据大小应该是646433*16=2162688位,换算成Kb应该是2162688/1024/8=264Kb,那我们再来看一下这个nifti文件的大小呢?如图所示,确实是265Kb。

image.png
image.png

至于nifti的int16与32float有什么区别,我觉得下面的这个回答还算满意(原文链接:https://afni.nimh.nih.gov/afni/community/board/read.php?1,137005,137007):


giuseppe pagnoni Wrote:


I have noticed that when copying NIFTI data (from
a Philips scanner) with 3dcopy, an automatic
conversion from INT16 to FLOAT32 seems to be
taking place [...]
But why is that
happening? Is there a way to keep the original
format? If the data are originally INT16, it
seems to me that you waste a lot of disk space and
computing time by doubling the size of the data
right away.

In my understanding int16 was used in AFNI in the old days, when disk space was expensive. Nowadays disk space is quite cheap, so it's not too much of an issue.

When using int16, data is stored together with a min value p and max value q; each value v is then stored as an int16 i with v=p + s*i, where s=(q-p)/(2^16-1) is the step size. When having a few outliers (extreme values) q-p is large so the step size s is large too. This reduces the resolution for the rest of the data (which is usually the data of interest). In addition, every processing step usually involves some averaging of existing values that have to be converted back to an int16, which again impoverishes the data (even if during computations the data is stored internally as float32).

Float32 does not have this disadvantage as it holds an exponent, allowing for a large range of data and yet good numerical precision.
Therefore float32 is currently considered as the preferred option by most.

Also note that you can enable compression which reduces file sizes considerably, and this compression works transparently in the AFNI programs. One way is to specify an extension for the output file (e.g. -prefix output.nii.gz to store in nifti and gzip the output). Another approach is to set the environmental variable AFNI_COMPRESSOR to BZIP2 or GZIP so that AFNI compresses the data automatically.


简单而言,就是如果你空间足够,还是用float32方便。

20190319

你可能感兴趣的:(关于nifti文件的int16和float32数据类型的问题)