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, 51);">   typedef itk::ExtractImageFilter&lt; RGBImageType, OutputImageType_extract_RGB &gt; FilterType_extract_RGB;</span><br>
    FilterType_extract_RGB::Pointer filter_extract_RGB = FilterType_extract_RGB::New();<br><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>
    } <br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; 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%;" id="avg_ls_inline_popup">
</div>