ITK icon indicating copy to clipboard operation
ITK copied to clipboard

Inconsistent read from `.mha` vector image

Open tbirdso opened this issue 3 years ago • 3 comments

Description

Behavior is observed where vector pixel data is read inconsistently from a small .mha data file.

Steps to Reproduce

  1. Download the data file from the ITKUltrasound data folder on Girder: rf_voltage_15_freq_0005000000_2017-5-31_12-36-44_ReferenceSpectrum_side_lines_03_fft1d_size_128.mha. The data file is a 3D image with a single voxel that is a 31-channel vector.
  2. Repeatedly read in the 31-channel vector image in Python and access the 29th or 30th channel
>>> import itk
>>> pixel_type = itk.VariableLengthVector[itk.F]
>>> image = itk.imread(r'path/to/rf_voltage_15_freq_0005000000_2017-5-31_12-36-44_ReferenceSpectrum_side_lines_03_fft1d_size_128.mha',pixel_type=pixel_type)
>>> image.GetPixel(0).GetElement(29)
1.2316740878152266e-39
>>> image = itk.imread(r'path/to/rf_voltage_15_freq_0005000000_2017-5-31_12-36-44_ReferenceSpectrum_side_lines_03_fft1d_size_128.mha',pixel_type=pixel_type)
>>> image.GetPixel(0).GetElement(29)
1.6303663969778794e+20
>>> image = itk.imread(r'path/to/rf_voltage_15_freq_0005000000_2017-5-31_12-36-44_ReferenceSpectrum_side_lines_03_fft1d_size_128.mha',pixel_type=pixel_type)
>>> image.GetPixel(0).GetElement(29)
1.6303663969778794e+20
>>> image = itk.imread(r'path/to/rf_voltage_15_freq_0005000000_2017-5-31_12-36-44_ReferenceSpectrum_side_lines_03_fft1d_size_128.mha',pixel_type=pixel_type)
>>> image.GetPixel(0).GetElement(29)
1.2316740878152266e-39

Expected behavior

Pixel output value is consistent

Actual behavior

Channel 29 alternates between 1.2316740878152266e-39 and 1.6303663969778794e+20

Channel 30 alternates between 2.1019476964872256e-44 and 0.15648820996284485

Reproducibility

Alternates evenly, approximately 50%

Versions

ITK 5.3rc03

Environment

Windows, Python 3.8.5

Additional Information

tbirdso avatar Feb 17 '22 20:02 tbirdso

Hi @aylward @jjomier, do either of you perhaps have thoughts on how best to investigate this issue with reading from a MetaImage file?

tbirdso avatar Feb 22 '22 21:02 tbirdso

@aylward let me know if I should investigate this. Looks like either the writing or reading of the file is incorrect (haven't tested C++)

jjomier avatar Feb 23 '22 15:02 jjomier

Weird!

I'm interested in where this inconsistency may be introduced.

  1. Try converting the file to .nii and see if the problem persists.
  2. Try converting the image to an array (and/or an array view) and see if the problem persists
  3. Try using an uncompressed metaimage...and see if the problem persists.
  4. Read it into a different variable every time (instead of overwriting image every time)...and see if the problem persists

I think that covers most of the points in the pipeline that could be introducing this bad behavior.

Thanks for finding this!!!

s

aylward avatar Feb 23 '22 16:02 aylward