<font size="2"><font face="verdana,sans-serif"><div><font size="2"><font face="verdana,sans-serif">I am not at work so at the moment so I cannot check your code in a compiler. However</font></font> your first error is inability to convert const into non-const value without using const_cast.</div>
</font></font><div><font size="2"><font face="verdana,sans-serif"><br></font></font></div><div><font size="2"><font face="verdana,sans-serif">For the second error you did not copy-paste the rest of the error message, namely the part "with TPixel=... and VImageDimension=...".</font></font></div>
<div><font size="2"><font face="verdana,sans-serif"><br></font></font></div><div><font size="2"><font face="verdana,sans-serif">Anyway I attached a source code of slice extracting program, you might find it useful.</font></font></div>
<div><font size="2"><font face="verdana,sans-serif"><br></font></font></div><div><font size="2"><font face="verdana,sans-serif">HTH<br></font></font><br><div class="gmail_quote">On Mon, May 30, 2011 at 14:38, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">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>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>