<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 &quot;with TPixel=... and VImageDimension=...&quot;.</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">&lt;<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>&gt;</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&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>
<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>