<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"><<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>></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: 'static_cast' : cannot convert from 'itk::RGBPixel<TComponent>' to 'unsigned char' </i>. Do you know what I am doing wrong?<br>
<br>Thanks in advance<br><br>///////// code //////////////<br>typedef itk::RGBPixel<unsigned char> RGBPixelType;<br> typedef itk::Image<RGBPixelType,3> RGBImageType;<br><br> typedef itk::ImageFileReader< RGBImageType > ReaderType_RGB;<br>
<br> ReaderType_RGB::Pointer reader_RGB = ReaderType_RGB::New();<br><br> reader_RGB->SetFileName( "output.hdr" );<br> reader_RGB->Update();<br><br><br> typedef unsigned char OutputPixelType_extract_RGB;<br>
typedef itk::Image< OutputPixelType_extract_RGB, 2 > OutputImageType_extract_RGB;<br><span style="background-color:rgb(255, 255, 255)"> typedef itk::ExtractImageFilter< RGBImageType, OutputImageType_extract_RGB > 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->GetOutput()->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->verticalScrollBar_z->setRange(0,size_z-1);<br> unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br> start[2] = 10; <br> <br><br> RGBImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br>
desiredRegion.SetIndex( start );<br><br> filter_extract_RGB->SetExtractionRegion( desiredRegion );<br><br> typedef itk::ImageFileWriter< OutputImageType_extract_RGB > WriterType_RGB;<br> WriterType_RGB::Pointer writer_RGB = WriterType_RGB::New();<br>
writer_RGB->SetFileName( "z.png" );<br><br> filter_extract_RGB->SetInput( reader_RGB->GetOutput() );<br> writer_RGB->SetInput( filter_extract_RGB->GetOutput() );<br><br> try <br> { <br>
writer_RGB->Update(); <br> } <br> catch( itk::ExceptionObject & err ) <br> { <br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err << 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>