Hello, I have written the following code using ITK abd Qt. I am using reader as global variable:<br><br> typedef unsigned char InputPixelType;<br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br>
typedef itk::ImageFileReader< InputImageType > ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br><br>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:<br>
<br><i>error C2440: 'initializing' : cannot convert from 'const itk::ImageRegion<VImageDimension>' to 'itk::ImageRegion<VImageDimension>'<br>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> *'</i><br>
<br>and this is the function:<br><br><br>void MainWindow::z_slice_extract()<br>{<br><br> typedef unsigned char InputPixelType;<br> typedef unsigned char OutputPixelType;<br><br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br>
typedef itk::Image< OutputPixelType, 2 > OutputImageType;<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br>
WriterType::Pointer writer = WriterType::New();<br><br> reader->SetFileName("C:/Users/manolis/Desktop/data/test.png");<br> <br> writer->SetFileName( "2D.png" );<br><br> <br> typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;<br>
FilterType::Pointer filter = FilterType::New();<br><br><br style="background-color: rgb(255, 255, 102);"><span style="background-color: rgb(255, 255, 102);"> InputImageType::RegionType inputRegion = reader->GetOutput()->GetLargestPossibleRegion();</span><br>
<br> InputImageType::SizeType size = inputRegion.GetSize();<br> <br> // get the size of the hole 3D image<br> unsigned long size_x = size[0];<br> unsigned long size_y = size[1];<br> unsigned long size_z = size[2];<br>
<br> // get slices of z coordiante<br> size[2] = 0; <br><br><br> InputImageType::IndexType start = inputRegion.GetIndex();<br><br> ui->verticalScrollBar_z->setRange(1,size_z);<br> unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br>
start[2] = sliceNumber;<br><br> <br><br> InputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br><br> filter->SetExtractionRegion( desiredRegion );<br>
<br><span style="background-color: rgb(255, 255, 102);"> filter->SetInput( reader->GetOutput() );</span><br> writer->SetInput( filter->GetOutput() );<br><br> try<br> {<br> writer->Update(); <br>
}<br> catch( itk::ExceptionObject & err )<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br> std::cerr << err << std::endl;<br> }<br><br><br><br> static QGraphicsPixmapItem* pixmapItem;<br>
<br> if (!pixmapItem) {<br> // pixmapItem = scene->addPixmap(QPixmap("2D.png"));<br><br> QPixmap tmpmap (QPixmap("2D.png"));<br> pixmapItem = scene->addPixmap ( tmpmap.scaled (214,256) );<br>
<br> ui->graphicsView_inputImage->setScene(scene);<br> } else {<br> QPixmap tmpmap (QPixmap("2D.png"));<br> pixmapItem->setPixmap(tmpmap.scaled ( 214,256));<br> }<br>
<br> <br><br><br> // taking the size of the loaded image<br> ui->label_4->setText(QString("size x:%1").arg(size_x));<br> ui->label_5->setText(QString("size y:%1").arg(size_y));<br>
ui->label_6->setText(QString("size z:%1").arg(size_z));<br><br> return;<br>}<br><br>