<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Change SYSTEM "https://itk.org/migrationv4/ITKMigration.dtd">

<!--**
**
** GDCMRescaleSlopeInterceptApplyOnWrite.xml
**
** Please, make sure this file validates the following w3c test before committing it: http://validator.w3.org
**-->
<Change>
    <!--**
    ** Title for the online migration page
    **-->
    <Title>
      Apply Rescale Slope / Intercept On Write with GDCMImageIO
    </Title>

    <!--**
    ** The author of the change
    **-->
    <Author>
      Matt McCormick
    </Author>

    <!--**
    ** Date of creation for the XML document
    **-->
    <Date>
      2014-09-18
    </Date>

    <!--**
    ** Plain text description of the change
    ** Extracted from git commit messages
    **-->
    <Description>
      <![CDATA[
      DICOM contains two tags, (0028,1052) the Rescale Intercept, and (0028,1053),
      to rescale values stored on disk to their real scalar range.  This is often used
      in CT images and it is often applied with PET images where the range of actual voxel
      values is outside the smaller integer value, like a two byte short, stored on disk.

      The GDCMImageIO will apply this rescaling on image read to deliver the true image
      values on output.

      GDCMImageIO would also apply the inverse rescaling operation on write, but a bug occurred
      around 2008 that compromised this behavior, which was fixed with ITK 4.6.0,
      released July 2014. Code that worked around this bug should be corrected.

      The GDCMImageIO now makes use of the InternalComponentType, which is the pixel type
      before rescale slope/intercept have been applied when reading from disk.

      This internal component and rescale slope from the reader can be used in
      a writer for the DICOM image with

      dicomWriter->SetImageIO( readersGDCMImageIO );
      dicomWriter->UseInputMetaDataDictionaryOff();

      The writer will re-use both the slope and intercept tag values, and the type used
      to store the original values on disk, the InternalComponentType.
      ]]>
    </Description>

    <!--**
    ** Sample code snippets
    ** Extracted from git diff of changed files in Examples and Testing
    **-->
    <SampleCode>
      <Old>
        <![CDATA[
        ////////////////////////////////////////////////
// 4) Shift data to undo the effect of a rescale intercept by the
//    DICOM reader
  std::string interceptTag("0028|1052");
  typedef itk::MetaDataObject< std::string > MetaDataStringType;
  itk::MetaDataObjectBase::Pointer entry = (*inputDict)[interceptTag];

  MetaDataStringType::ConstPointer interceptValue =
    dynamic_cast<const MetaDataStringType *>( entry.GetPointer() ) ;

  int interceptShift = 0;
  if( interceptValue )
    {
    std::string tagValue = interceptValue->GetMetaDataObjectValue();
    interceptShift = -atoi ( tagValue.c_str() );
    }

  ShiftScaleType::Pointer shiftScale = ShiftScaleType::New();
  shiftScale->SetInput( resampler->GetOutput());
  shiftScale->SetShift( interceptShift );
        ]]>
      </Old>

      <New>
        <![CDATA[
// No manual rescaling is required if the GDCMImageIO instance is re-used.
        ]]>
      </New>

    </SampleCode>

    <!--**
    ** The change-ids for all commits in the topic branch
    **-->
    <Gerrit-ChangeId>
      I1cecec83d2bfeac5a8e64b77062a46dcd49746f7
    </Gerrit-ChangeId>

    <!--**
    ** List of all changed files from the topic branch
    **-->
    <FileList>
      Modules/IO/GDCM/include/itkGDCMImageIO.h
      Modules/IO/GDCM/src/itkGDCMImageIO.cxx
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest2Baseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest2RescaledBaseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest3Baseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest3RescaledBaseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest4Baseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTest4RescaledBaseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTestBaseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTestRescaledBaseline.mha.md5
      Modules/IO/GDCM/test/Baseline/itkGDCMImageIOTestRescaledBaseline.mha.md5.tmp
      Modules/IO/GDCM/test/CMakeLists.txt
      Modules/IO/GDCM/test/itkGDCMImageIOTest.cxx
      Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRescaler.cxx
    </FileList>

</Change>
