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

fiji
imagej

#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


#6

Hello Herbie,

Thank you for the information. From the ImageJ website, I see:
https://imagej.nih.gov/ij/docs/guide/146-7.html#sec:Image-Types

32-bit Images that can display 4, 294, 967, 296 (232) gray levels (real numbers). In 32-bit images, pixels are described by floating point values and can have any intensity value including NaN[?] (Not a Number).

I think this statement is a little misleading, as 32-bit float pixels cannot have any intensity value desired.

I am using the Fiji distribution of ImageJ.
I was opening the mha and nrrd files by dragging and dropping.

The same behavior is found using the SCIFIO library for openning the nrrd images.

Adam


#7

Good day Adam,

at least your citation, as it appears above, is misleading …

[…] 32-bit float pixels cannot have any intensity value desired.

What do you like to tell us by this statement?

Here
https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3
you may get more information about the Java 32bit float number format.

ImageJ-plugin you use to read images in the mentioned formats “.mha” and “.nrrd”.

Frankly speaking, I never mentioned that I read image in these formats. I have no idea how to deal with these formats but perhaps Bioformats may help.

Regards

Herbie


#8

Basically, the data got corrupted. Did you have any backup for the system files? If not you can use hard drive data recovery tools that might restore the lost data files. Some I can suggest is Stellar Phoenix, EaseUs, etc.