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&lt; InputPixelType,  3 &gt;    InputImageType;<br>
  typedef itk::ImageFileReader&lt; InputImageType  &gt;  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: &#39;initializing&#39; : cannot convert from &#39;const itk::ImageRegion&lt;VImageDimension&gt;&#39; to &#39;itk::ImageRegion&lt;VImageDimension&gt;&#39;<br>error C2664: &#39;void itk::ImageToImageFilter&lt;TInputImage,TOutputImage&gt;::SetInput(const itk::Image&lt;TPixel,VImageDimension&gt; *)&#39; : cannot convert parameter 1 from &#39;itk::Image&lt;TPixel,VImageDimension&gt; *&#39; to &#39;const itk::Image&lt;TPixel,VImageDimension&gt; *&#39;</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&lt; InputPixelType,  3 &gt;    InputImageType;<br>
  typedef itk::Image&lt; OutputPixelType, 2 &gt;    OutputImageType;<br><br>  typedef itk::ImageFileReader&lt; InputImageType  &gt;  ReaderType;<br>  typedef itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br><br>
  WriterType::Pointer writer = WriterType::New();<br><br>  reader-&gt;SetFileName(&quot;C:/Users/manolis/Desktop/data/test.png&quot;);<br>  <br>  writer-&gt;SetFileName( &quot;2D.png&quot; );<br><br>  <br>  typedef itk::ExtractImageFilter&lt; InputImageType, OutputImageType &gt; 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-&gt;GetOutput()-&gt;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-&gt;verticalScrollBar_z-&gt;setRange(1,size_z);<br>  unsigned int sliceNumber  =  ui-&gt;verticalScrollBar_z-&gt;value();<br>
  start[2] = sliceNumber;<br><br> <br><br>  InputImageType::RegionType desiredRegion;<br>  desiredRegion.SetSize( size );<br>  desiredRegion.SetIndex( start );<br><br>  filter-&gt;SetExtractionRegion( desiredRegion );<br>
<br><span style="background-color: rgb(255, 255, 102);">  filter-&gt;SetInput( reader-&gt;GetOutput() );</span><br>  writer-&gt;SetInput( filter-&gt;GetOutput() );<br><br>      try<br>    {<br>    writer-&gt;Update();    <br>
    }<br>    catch( itk::ExceptionObject &amp; err )<br>    {<br>    std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; err &lt;&lt; std::endl;<br>    }<br><br><br><br>     static QGraphicsPixmapItem* pixmapItem;<br>
<br>     if (!pixmapItem) {<br>        //    pixmapItem = scene-&gt;addPixmap(QPixmap(&quot;2D.png&quot;));<br><br>          QPixmap tmpmap (QPixmap(&quot;2D.png&quot;));<br>        pixmapItem = scene-&gt;addPixmap ( tmpmap.scaled (214,256) );<br>
<br>            ui-&gt;graphicsView_inputImage-&gt;setScene(scene);<br>        } else {<br>            QPixmap tmpmap (QPixmap(&quot;2D.png&quot;));<br>            pixmapItem-&gt;setPixmap(tmpmap.scaled ( 214,256));<br>        }<br>
<br>    <br><br><br>    // taking the size of the loaded image<br>    ui-&gt;label_4-&gt;setText(QString(&quot;size x:%1&quot;).arg(size_x));<br>    ui-&gt;label_5-&gt;setText(QString(&quot;size y:%1&quot;).arg(size_y));<br>
    ui-&gt;label_6-&gt;setText(QString(&quot;size z:%1&quot;).arg(size_z));<br><br>    return;<br>}<br><br>