MantisBT - ITK
View Issue Details
0007773ITKpublic2008-10-02 13:502008-10-03 12:17
Johannes Perl 
Bill Lorensen 
normalminoralways
closedfixed 
LinuxKubuntu 8.04Kernel 2.6.24-19
ITK-3-8 
 
0007773: bitmap images can not be read as RGB
Some bitmap images can not be read as RGB images, due to a bug in BMPImageIO.

If the bitmap images are read, the single color values get lost and are translated into greyscale values.

The problem was already reproduced and investigated by Bill Lorensen.
"The BMPImageIO is not properly generating a lookup table when the number
of colors == 0. It should generate a lookup table based on the depth
of the image."
Use the following code and compile it. Then call ./RGBTest 000.bmp with the uploaded image being in the same folder.

The output will be:
Pixel values from GetRed,GetGreen,GetBlue:
Red = 36
Green = 36
Blue = 36
Pixel values:
Red = 36
Green = 36
Blue = 36

//file RGBTest.cxx
#include "itkImage.h"
#include "itkImageFileReader.h"

#include "itkRGBPixel.h"

int main( int , char * argv[] )
{
  typedef itk::RGBPixel< unsigned char > PixelType;
  typedef itk::Image< PixelType, 2 > ImageType;
  typedef itk::ImageFileReader< ImageType > ReaderType;
  
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->Update();

  ImageType::Pointer image = reader->GetOutput();

  ImageType::IndexType pixelIndex;

  pixelIndex[0] = 3;
  pixelIndex[1] = 3;

  PixelType onePixel = image->GetPixel( pixelIndex );
  
  PixelType::ValueType red = onePixel.GetRed();
  PixelType::ValueType green = onePixel.GetGreen();
  PixelType::ValueType blue = onePixel.GetBlue();

  std::cout << "Pixel values from GetRed,GetGreen,GetBlue:" << std::endl;
  std::cout << "Red = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(red)
      << std::endl;
  std::cout << "Green = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(green)
      << std::endl;
  std::cout << "Blue = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
      << std::endl;

  red = onePixel[0]; // extract Red component
  green = onePixel[1]; // extract Green component
  blue = onePixel[2]; // extract Blue component

  std::cout << "Pixel values:" << std::endl;
  std::cout << "Red = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(red)
      << std::endl;
  std::cout << "Green = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(green)
      << std::endl;
  std::cout << "Blue = "
      << itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
      << std::endl;
 
  return 0;
}

//CMakeLists.txt
PROJECT(RGBTest)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)

ADD_EXECUTABLE(RGBTest RGBTest.cxx )

TARGET_LINK_LIBRARIES(RGBTest ITKCommon ITKIO)
No tags attached.
? 0001001_os_sn6040.bmp (590,902) 2008-10-02 13:50
https://public.kitware.com/Bug/file/1745/0001001_os_sn6040.bmp
Issue History
2008-10-02 13:50Johannes PerlNew Issue
2008-10-02 13:50Johannes PerlFile Added: 0001001_os_sn6040.bmp
2008-10-02 14:23Bill LorensenStatusnew => assigned
2008-10-02 14:23Bill LorensenAssigned To => Bill Lorensen
2008-10-02 14:27Bill LorensenNote Added: 0013713
2008-10-02 14:27Bill LorensenStatusassigned => acknowledged
2008-10-03 12:11Bill LorensenResolutionopen => fixed
2008-10-03 12:12Bill LorensenStatusacknowledged => resolved
2008-10-03 12:17Bill LorensenStatusresolved => feedback
2008-10-03 12:17Bill LorensenResolutionfixed => reopened
2008-10-03 12:17Bill LorensenNote Added: 0013723
2008-10-03 12:17Bill LorensenStatusfeedback => closed
2008-10-03 12:17Bill LorensenResolutionreopened => fixed

Notes
(0013713)
Bill Lorensen   
2008-10-02 14:27   
I used the example provided by the reporter along with a sample image he provided. As he reports, the values are reported as grayscale, the color being lost.

I tracked down the problem in itkBMPImageIO.cxx. The code does not correctly compute a lookup table when the number of colors is 0. Also, the Allow8Bit mode interferes with a corrected implementation. It seems this mode should always be false in itk since the reader will convert rgb images to scalars.
(0013723)
Bill Lorensen   
2008-10-03 12:17   
The code was not correctly create a color table if the depth was 8. Corrected in cvs entries:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkBMPImageIO.cxx?root=Insight&r1=1.28&r2=1.29&sortby=date [^]

http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/IO/itkBMPImageIO.h?root=Insight&r1=1.8&r2=1.9&sortby=date [^]