Precision of 32-bit images (read and saving) - data loss

Tags: #<Tag:0x00007fd54032c360>



I have encountered a problem with the corruption of values in 32-bit images and subsequent saving. The reading of values in 32-bit .mha or .nrrd files does not appear to be accurate. The displayed values when hovering the mouse over the pixels are not correct, and when saving the files as .tif, .nrrd, or .mha there is data loss. Is this a known precision error with 32-bit data?

imagej 1.51s
windows 10

Thank you


Can you provide an example or a screenshot?


Hello Gabriel,

If I generate example images (image.mha, image.nrrd) using python and simpleITK using the following script

import SimpleITK as sitk

img = sitk.Image(64,64,sitk.sitkUInt32)
for r in range(64/3):
   for c in range(64/3):
sitk.WriteImage(img,'image' + '.mha')
sitk.WriteImage(img,'image' + '.nrrd')

When I hover over the images in Imagej or measure the values. I do not get 182305713.


This is probably more telling

import SimpleITK as sitk

img = sitk.Image(1024,64,sitk.sitkUInt32)
for r in range(1024):
    for c in range(64):

sitk.WriteImage(img,'image' + '.mha')
sitk.WriteImage(img,'image' + '.nrrd')

imagej reads this as jumps of values of 16 between ‘vertical bars’, which should look like a continuous gradient.

Could this be something in the way I am encoding the mha or nrrd files that I dont know about?


Good day Adam,

did you consider the image formats that at least ImageJ-1 supports?

is the link to the ImageJ user guide.

Achromatic formats are 8bit and 16bit unsigned which cannot handle the large values you are interested in. Furthermore, there is the 32bit float format which handles an enormous range, including negative numbers but only with up to 7 or 8 decimals.

I don’t know about the image formats ImageJ-2 can handle and what kind of ImageJ-plugin you use to read images in the mentioned formats “.mha” and “.nrrd”.