Skip to content
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

oldmin/oldmax aren't handled properly #582

tashrifbillah opened this Issue Mar 11, 2019 · 2 comments


None yet
3 participants
Copy link

tashrifbillah commented Mar 11, 2019


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.
dcm2niix should do the DICOM-->NIFTI conversion for you. Then you can use conversion repository to convert NIFTI-->NHDR


This comment has been minimized.

Copy link

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 label Mar 14, 2019


This comment has been minimized.

Copy link

thewtex commented Mar 14, 2019

CC: @dzenanz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.