[Insight-users] error C2440: 'initializing' : cannot convert from 'const itk::ImageRegion<VImageDimension>' to 'itk::ImageRegion<VImageDimension>'

john smith mkitkinsightuser at gmail.com
Mon May 30 08:38:56 EDT 2011


Hello, I have written the following code using ITK abd Qt. I am using reader
as global variable:

      typedef unsigned char        InputPixelType;
  typedef itk::Image< InputPixelType,  3 >    InputImageType;
  typedef itk::ImageFileReader< InputImageType  >  ReaderType;
  ReaderType::Pointer reader = ReaderType::New();

In my program I have two function. In the first, my program identifies the
reader as global variable, but in the second I get these errors:

*error C2440: 'initializing' : cannot convert from 'const
itk::ImageRegion<VImageDimension>' to 'itk::ImageRegion<VImageDimension>'
error C2664: 'void
itk::ImageToImageFilter<TInputImage,TOutputImage>::SetInput(const
itk::Image<TPixel,VImageDimension> *)' : cannot convert parameter 1 from
'itk::Image<TPixel,VImageDimension> *' to 'const
itk::Image<TPixel,VImageDimension> *'*

and this is the function:


void MainWindow::z_slice_extract()
{

  typedef unsigned char        InputPixelType;
  typedef unsigned char        OutputPixelType;

  typedef itk::Image< InputPixelType,  3 >    InputImageType;
  typedef itk::Image< OutputPixelType, 2 >    OutputImageType;

  typedef itk::ImageFileReader< InputImageType  >  ReaderType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;

  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName("C:/Users/manolis/Desktop/data/test.png");

  writer->SetFileName( "2D.png" );


  typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
FilterType;
  FilterType::Pointer filter = FilterType::New();


  InputImageType::RegionType inputRegion =
reader->GetOutput()->GetLargestPossibleRegion();

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

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

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


  InputImageType::IndexType start = inputRegion.GetIndex();

  ui->verticalScrollBar_z->setRange(1,size_z);
  unsigned int sliceNumber  =  ui->verticalScrollBar_z->value();
  start[2] = sliceNumber;



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

  filter->SetExtractionRegion( desiredRegion );

  filter->SetInput( reader->GetOutput() );
  writer->SetInput( filter->GetOutput() );

      try
    {
    writer->Update();
    }
    catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    }



     static QGraphicsPixmapItem* pixmapItem;

     if (!pixmapItem) {
        //    pixmapItem = scene->addPixmap(QPixmap("2D.png"));

          QPixmap tmpmap (QPixmap("2D.png"));
        pixmapItem = scene->addPixmap ( tmpmap.scaled (214,256) );

            ui->graphicsView_inputImage->setScene(scene);
        } else {
            QPixmap tmpmap (QPixmap("2D.png"));
            pixmapItem->setPixmap(tmpmap.scaled ( 214,256));
        }




    // taking the size of the loaded image
    ui->label_4->setText(QString("size x:%1").arg(size_x));
    ui->label_5->setText(QString("size y:%1").arg(size_y));
    ui->label_6->setText(QString("size z:%1").arg(size_z));

    return;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110530/786c128e/attachment.htm>


More information about the Insight-users mailing list