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

fiji
Tags: #<Tag:0x00007fd54032c360>

#1

Hello,

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


#2

Can you provide an example or a screenshot?


#3

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):
        img.SetPixel(r,c,182305713)
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.


#4

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):
        img.SetPixel(r,c,182305700+r)

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?


#5

Good day Adam,

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

Here
https://imagej.nih.gov/ij/docs/guide/index.html
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”.

Regards

Herbie