<div>Do you really expect the filter to extract a 2D image of unsigned char pixels from a 3D image of RGB pixels?</div><div><br></div><div><div class="gmail_quote">On Thu, Jun 30, 2011 at 3:07 PM, 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 to all,<br><br>I am trying to read an RGB image, then use the 
ExtractImageFilter and finally, write the RGB slice. I have written the 
following code, but I get this error <br><i>error C2440: &#39;static_cast&#39; : cannot convert from &#39;itk::RGBPixel&lt;TComponent&gt;&#39; to &#39;unsigned char&#39; </i>. Do you know what I am doing wrong?<br>
<br>Thanks in advance<br><br>///////// code //////////////<br>typedef itk::RGBPixel&lt;unsigned char&gt; RGBPixelType;<br>  typedef itk::Image&lt;RGBPixelType,3&gt; RGBImageType;<br><br>   typedef  itk::ImageFileReader&lt; RGBImageType &gt; ReaderType_RGB;<br>


<br>     ReaderType_RGB::Pointer reader_RGB = ReaderType_RGB::New();<br><br>     reader_RGB-&gt;SetFileName( &quot;output.hdr&quot;  );<br>     reader_RGB-&gt;Update();<br><br><br>  typedef unsigned char       OutputPixelType_extract_RGB;<br>


  typedef itk::Image&lt; OutputPixelType_extract_RGB, 2 &gt;    OutputImageType_extract_RGB;<br><span style="background-color:rgb(255, 255, 255)">   typedef itk::ExtractImageFilter&lt; RGBImageType, OutputImageType_extract_RGB &gt; FilterType_extract_RGB;</span><br>


    <span style="background-color:rgb(255, 255, 51)">FilterType_extract_RGB::Pointer filter_extract_RGB = FilterType_extract_RGB::New();</span><br><div><br>  RGBImageType::RegionType inputRegion =<br>          reader_RGB-&gt;GetOutput()-&gt;GetLargestPossibleRegion();<br>

<br><br>  RGBImageType::SizeType size = inputRegion.GetSize();<br>
 <br>  // get the size of the hole 3D image<br>  size_x = size[0];<br>  size_y = size[1];<br>   size_z = size[2];<br>  <br>  // get slices of z coordiante<br>  size[2] = 0; <br><br>   RGBImageType::IndexType start = inputRegion.GetIndex();<br>


  ui-&gt;verticalScrollBar_z-&gt;setRange(0,size_z-1);<br>  unsigned int sliceNumber = ui-&gt;verticalScrollBar_z-&gt;value();<br>  start[2] = 10; <br> <br><br>  RGBImageType::RegionType desiredRegion;<br>  desiredRegion.SetSize( size );<br>


  desiredRegion.SetIndex( start );<br><br>  filter_extract_RGB-&gt;SetExtractionRegion( desiredRegion );<br><br>    typedef  itk::ImageFileWriter&lt; OutputImageType_extract_RGB  &gt; WriterType_RGB;<br>     WriterType_RGB::Pointer writer_RGB = WriterType_RGB::New();<br>


    writer_RGB-&gt;SetFileName( &quot;z.png&quot; );<br><br>   filter_extract_RGB-&gt;SetInput( reader_RGB-&gt;GetOutput() );<br>   writer_RGB-&gt;SetInput( filter_extract_RGB-&gt;GetOutput() );<br><br>    try <br>    { <br>


    writer_RGB-&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>


    } </div><div style="padding:0px;margin-left:0px;margin-top:0px;overflow:hidden;word-wrap:break-word;color:black;font-size:10px;text-align:left;line-height:130%">
</div>
<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>