Ok, I guess that you just want to extract an RGB 2D slice from a 3D RGB image. <br><br>Then, your mistake is OutputPixelType. RGBPixels are vectors of unsigned chars, and can&#39;t be directly converted to scalars (just unsigned chars). The fastest fix could be this:<br>
<br>  typedef itk::Image&lt;RGBPixelType,2&gt;       OutputPixelType_extract_RGB;<br><br>By the way, you probably missed writer-&gt;SetFileName() in your code ;)<br><br>HTH<br><br><br><br><div class="gmail_quote">2011/7/1 john smith <span dir="ltr">&lt;<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Well, to explain what I am trying to do. I have created a 3D RGB image as a result of a segmentation procedure. To create this image I had used itkLabelOverlayImageFilter.So this image was created by a greyscale image and a label image, so I get the result of the initial greyscale image and the label image with blue color. When I have tried to extract a slice from the image  I got 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>. I have included my code in the begining of this topic. I also cannot understand the second step very well.Why I should do something like this? What should I do for this task?<br>

<br>Thanks for your response<div><div></div><div class="h5"><br><br><br><div class="gmail_quote">2011/7/1 Juan Vidal <span dir="ltr">&lt;<a href="mailto:juanvidalallende@gmail.com" target="_blank">juanvidalallende@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
Well, I don&#39;t know exactly what your are trying to do, but in my opinion you could probably split your problem:<br><br>1) Extract the desired 2D RGB slice from the 3D RGB image (ExtractImageFilter should work).<br>2) Convert the 2D RGB slice to unsigned char<br>


<br>The second point depends on the purpose of your application. You might want to extract one of the channels, or perhaps convert the RGB image to grayscale in some fashion...<br><br>HTH<div><div></div><div><br>
<br><br><br><div class="gmail_quote">
2011/6/30 john smith <span dir="ltr">&lt;<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">


Could somebody explain in some words what must be done in order to extract a 2D slice from a RGB 3D image? I am trying to find an example (but I didn&#39;t find anything) and I am reading the docs but I am totally lost. This task may be very easy but I really need some help.<br>



Any response would be very useful.<br><br>Thanks in advace<div><div></div><div><br><br><div class="gmail_quote">2011/6/30 john smith <span dir="ltr">&lt;<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">You may have right as it should work properly.It is the first time I am working with RGB images. But what changes should be done?<br>



<br>Thanks for yoyr response<div><div></div><div><br><br><div class="gmail_quote">2011/6/30 robert tamburo <span dir="ltr">&lt;<a href="mailto:robert.tamburo@gmail.com" target="_blank">robert.tamburo@gmail.com</a>&gt;</span><br>




<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><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"><div><div></div><div>On Thu, Jun 30, 2011 at 3:07 PM, john smith <span dir="ltr">&lt;<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>&gt;</span> wrote:<br>





</div></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div><div></div><div>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></div></div>_____________________________________<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>
</blockquote></div><br><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>
</div></div></blockquote></div><br><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>
</div></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><br clear="all"><br></div></div><font color="#888888">-- <br>Juan Vidal Allende<br>
</font></blockquote></div><br><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Juan Vidal Allende<br>