Skip to content

oldmin/oldmax aren't handled properly #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tashrifbillah opened this issue Mar 11, 2019 · 3 comments
Open

oldmin/oldmax aren't handled properly #582

tashrifbillah opened this issue Mar 11, 2019 · 3 comments
Assignees
Labels
area:IO Issues affecting the IO module Good first issue A good issue for community members new to contributing type:Enhancement Improvement of existing methods or implementation

Comments

@tashrifbillah
Copy link

Description

cc: @jcfr @lassoan @pieper

Nifti1 has scl_slope and scl_inter. The equivalent attributes in the NRRD are oldmin and oldmax as if:

    # define oldmin and oldmax when scl_slope and scl_inter are present
    img= nibabel.load('filename')
    dtype= img.header.get_data_dtype().name
    scl_slope= img.dataobj.slope
    scl_inter= img.dataobj.inter

    if scl_slope!=1.0 or scl_inter!=0:
        info= np.iinfo(dtype)
        oldmin= info.min*scl_slope+scl_inter
        oldmax= info.max*scl_slope+scl_inter
        print(f'old min: {oldmin}')
        print(f'old max: {oldmax}')

(you can also look at this commit by Chris Rorden)

Actual behavior

However, after I defined old min and old max in the NRRD header, the data reported in Slicer aren't scaled. The difference becomes stark when you load both NIFTI and NRRD image in Slicer. NIFTI voxels are scaled while NRRD aren't. On the other hand, fslview, NIBABEL both report the data after scaling.

Expected behavior

So, we should report NRRD data after scaling them as follows:

find scl_slope and scl_inter from above and
scaled_data= unscaled_data*scl_slope+ scl_inter

Additional Information

Work with the following public data: the T1_echo*.nii.gz have scaling present in the NIFTI.
http://people.cas.sc.edu/rorden/SW/dcm2niix/odd/multiechotest_Philips_Vanderbilt.zip
dcm2niix should do the DICOM-->NIFTI conversion for you. Then you can use conversion repository to convert NIFTI-->NHDR

@tashrifbillah tashrifbillah added the type:Enhancement Improvement of existing methods or implementation label Mar 11, 2019
@pieper
Copy link
Contributor

pieper commented Mar 11, 2019

A rough draft of a fix (not tested) for this issue would be to add the code below to itkNrrdImageIO.

  if (AIR_EXISTS(nrrd->oldMin) && AIR_EXISTS(nrrd->oldMax && nrrd->oldMin != AIR_NAN && nrrd->oldMax != AIR_NAN)) 
    {
      Nrrd *ntmp = nrrdNew();
      if ( nrrdUnquatize(nrrd, ntmp) )
        {
        char *err = biffGetDone(NRRD); // would be nice to free(err)
        itkExceptionMacro("Read: Error unquantizing:\n" << err);
        }
      if ( nrrdCopy(ntmp, nrrd) )
        {
        char *err = biffGetDone(NRRD); // would be nice to free(err)
        itkExceptionMacro("Read: Error copying:\n" << err);
        }
    }

@thewtex thewtex added the area:IO Issues affecting the IO module label Mar 14, 2019
@thewtex
Copy link
Member

thewtex commented Mar 14, 2019

CC: @dzenanz

@dzenanz dzenanz added the Good first issue A good issue for community members new to contributing label Apr 9, 2019
@hjmjohnson hjmjohnson added this to the ITK 6.0 Beta 1 milestone Jan 23, 2025
@jadh4v
Copy link
Member

jadh4v commented Jan 23, 2025

working on this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:IO Issues affecting the IO module Good first issue A good issue for community members new to contributing type:Enhancement Improvement of existing methods or implementation
Projects
None yet
Development

No branches or pull requests

7 participants