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 id=":119"><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="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>