[Insight-users] error when using extract image filter for RGB image

john smith mkitkinsightuser at gmail.com
Thu Jun 30 13:16:59 EDT 2011


Hello to all,

I am trying to read an RGB image, then use the ExtractImageFilter and
finally, write the RGB slice. I have written the following code, but I get
this error
*error C2440: 'static_cast' : cannot convert from
'itk::RGBPixel<TComponent>' to 'unsigned char' *. Do you know what I am
doing wrong?

Thanks in advance

///////// code //////////////
typedef itk::RGBPixel<unsigned char> RGBPixelType;
  typedef itk::Image<RGBPixelType,3> RGBImageType;

   typedef  itk::ImageFileReader< RGBImageType > ReaderType_RGB;

     ReaderType_RGB::Pointer reader_RGB = ReaderType_RGB::New();

     reader_RGB->SetFileName( "output.hdr"  );
     reader_RGB->Update();


  typedef unsigned char       OutputPixelType_extract_RGB;
  typedef itk::Image< OutputPixelType_extract_RGB, 2 >
OutputImageType_extract_RGB;
   typedef itk::ExtractImageFilter< RGBImageType,
OutputImageType_extract_RGB > FilterType_extract_RGB;
    FilterType_extract_RGB::Pointer filter_extract_RGB =
FilterType_extract_RGB::New();

  RGBImageType::RegionType inputRegion =
          reader_RGB->GetOutput()->GetLargestPossibleRegion();


  RGBImageType::SizeType size = inputRegion.GetSize();

  // get the size of the hole 3D image
  size_x = size[0];
  size_y = size[1];
   size_z = size[2];

  // get slices of z coordiante
  size[2] = 0;

   RGBImageType::IndexType start = inputRegion.GetIndex();
  ui->verticalScrollBar_z->setRange(0,size_z-1);
  unsigned int sliceNumber = ui->verticalScrollBar_z->value();
  start[2] = 10;


  RGBImageType::RegionType desiredRegion;
  desiredRegion.SetSize( size );
  desiredRegion.SetIndex( start );

  filter_extract_RGB->SetExtractionRegion( desiredRegion );

    typedef  itk::ImageFileWriter< OutputImageType_extract_RGB  >
WriterType_RGB;
     WriterType_RGB::Pointer writer_RGB = WriterType_RGB::New();
    writer_RGB->SetFileName( "z.png" );

   filter_extract_RGB->SetInput( reader_RGB->GetOutput() );
   writer_RGB->SetInput( filter_extract_RGB->GetOutput() );

    try
    {
    writer_RGB->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110630/c678264c/attachment.htm>


More information about the Insight-users mailing list