[Insight-developers] Bug in itk::GDCMImageIO

Luis Ibanez luis.ibanez at kitware.com
Fri Apr 11 12:50:47 EDT 2008


Hi Mathieu,

Thanks a lot for providing this patch.

It has now been committed to CVS.


    Thanks


        Luis


-------------------------
Mathieu Malaterre wrote:
> Hi there,
> 
>   Simon Warfield recently send me a DICOM file that produce a seg
> fault when reading it using itk::GDCMImageIO. Basically the header
> declares itself as single component, but provide a Lookup Table to
> convert to RGB. GDCM got lost and return incompatible results.
>   Please consider applying the attached patch before next ITK release.
> 
> Thanks,
> 
> 
> ------------------------------------------------------------------------
> 
> Index: Code/IO/itkGDCMImageIO.cxx
> ===================================================================
> RCS file: /cvsroot/Insight/Insight/Code/IO/itkGDCMImageIO.cxx,v
> retrieving revision 1.134
> diff -u -r1.134 itkGDCMImageIO.cxx
> --- Code/IO/itkGDCMImageIO.cxx	25 Jan 2008 00:00:05 -0000	1.134
> +++ Code/IO/itkGDCMImageIO.cxx	10 Apr 2008 09:04:03 -0000
> @@ -553,6 +553,11 @@
>    gdcm::FileHelper gfile(header);
>  
>    size_t size = gfile.GetImageDataSize();
> +  // Handle nasty case, where header says: single scalar but provides a LUT
> +  if( header->HasLUT() && m_NumberOfComponents == 1 )
> +    {
> +    size = gfile.GetImageDataRawSize();
> +    }
>    unsigned char *source = (unsigned char*)gfile.GetImageData();
>  
>    // We can rescale pixel only in grayscale image
> @@ -786,24 +791,24 @@
>          m_ComponentType = UNKNOWNCOMPONENTTYPE;
>          break;
>        }
> -    }
> -  // Handle here the special case where we are dealing with 12bits data :
> -  if( header->GetEntryValue(0x0028, 0x0101) == "12" ) // Bits Stored
> -    {
> -    std::string sign = header->GetEntryValue(0x0028, 0x0103); // Pixel Representation
> -    if ( sign == "0" )
> -      {
> -      m_ComponentType = 
> -        IntervalCalculator<Pixel16_12_11_0, ICDirect>::Compute(m_RescaleSlope, m_RescaleIntercept);
> -      }
> -    else if ( sign == "1" )
> -      {
> -      m_ComponentType = 
> -        IntervalCalculator<Pixel16_12_11_1, ICDirect>::Compute(m_RescaleSlope, m_RescaleIntercept);
> -      }
> -    else
> +    // Handle here the special case where we are dealing with 12bits data :
> +    if( header->GetEntryValue(0x0028, 0x0101) == "12" ) // Bits Stored
>        {
> -      itkExceptionMacro(<< "Pixel Representation cannot be handled: " << sign );
> +      std::string sign = header->GetEntryValue(0x0028, 0x0103); // Pixel Representation
> +      if ( sign == "0" )
> +        {
> +        m_ComponentType = 
> +          IntervalCalculator<Pixel16_12_11_0, ICDirect>::Compute(m_RescaleSlope, m_RescaleIntercept);
> +        }
> +      else if ( sign == "1" )
> +        {
> +        m_ComponentType = 
> +          IntervalCalculator<Pixel16_12_11_1, ICDirect>::Compute(m_RescaleSlope, m_RescaleIntercept);
> +        }
> +      else
> +        {
> +        itkExceptionMacro(<< "Pixel Representation cannot be handled: " << sign );
> +        }
>        }
>      }
>  
> Index: Utilities/gdcm/src/gdcmFile.cxx
> ===================================================================
> RCS file: /cvsroot/Insight/Insight/Utilities/gdcm/src/gdcmFile.cxx,v
> retrieving revision 1.21
> diff -u -r1.21 gdcmFile.cxx
> --- Utilities/gdcm/src/gdcmFile.cxx	24 May 2007 07:26:20 -0000	1.21
> +++ Utilities/gdcm/src/gdcmFile.cxx	10 Apr 2008 09:04:04 -0000
> @@ -1419,7 +1419,7 @@
>  
>     std::string strPhotometricInterpretation = GetEntryValue(0x0028,0x0004);
>  
> -   if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
> +   if ( Util::DicomStringEqual(strPhotometricInterpretation, "PALETTE COLOR") )
>     {
>        if ( HasLUT() )// PALETTE COLOR is NOT enough
>        {
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list