[Insight-users] extract slice from RGB image

robert tamburo robert.tamburo at gmail.com
Thu Jun 30 15:21:35 EDT 2011


Do you really expect the filter to extract a 2D image of unsigned char
pixels from a 3D image of RGB pixels?

On Thu, Jun 30, 2011 at 3:07 PM, john smith <mkitkinsightuser at gmail.com>wrote:

> Hello to all,
>
> 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
> *error C2440: 'static_cast' : cannot convert from
> 'itk::RGBPixel<TComponent>' to 'unsigned char' *. Do you know what I am
> doing wrong?
>
> Thanks in advance
>
> ///////// code //////////////
> typedef itk::RGBPixel<unsigned char> RGBPixelType;
>   typedef itk::Image<RGBPixelType,3> RGBImageType;
>
>    typedef  itk::ImageFileReader< RGBImageType > ReaderType_RGB;
>
>      ReaderType_RGB::Pointer reader_RGB = ReaderType_RGB::New();
>
>      reader_RGB->SetFileName( "output.hdr"  );
>      reader_RGB->Update();
>
>
>   typedef unsigned char       OutputPixelType_extract_RGB;
>   typedef itk::Image< OutputPixelType_extract_RGB, 2 >
> OutputImageType_extract_RGB;
>    typedef itk::ExtractImageFilter< RGBImageType,
> OutputImageType_extract_RGB > FilterType_extract_RGB;
>     FilterType_extract_RGB::Pointer filter_extract_RGB =
> FilterType_extract_RGB::New();
>
>   RGBImageType::RegionType inputRegion =
>           reader_RGB->GetOutput()->GetLargestPossibleRegion();
>
>
>   RGBImageType::SizeType size = inputRegion.GetSize();
>
>   // get the size of the hole 3D image
>   size_x = size[0];
>   size_y = size[1];
>    size_z = size[2];
>
>   // get slices of z coordiante
>   size[2] = 0;
>
>    RGBImageType::IndexType start = inputRegion.GetIndex();
>   ui->verticalScrollBar_z->setRange(0,size_z-1);
>   unsigned int sliceNumber = ui->verticalScrollBar_z->value();
>   start[2] = 10;
>
>
>   RGBImageType::RegionType desiredRegion;
>   desiredRegion.SetSize( size );
>   desiredRegion.SetIndex( start );
>
>   filter_extract_RGB->SetExtractionRegion( desiredRegion );
>
>     typedef  itk::ImageFileWriter< OutputImageType_extract_RGB  >
> WriterType_RGB;
>      WriterType_RGB::Pointer writer_RGB = WriterType_RGB::New();
>     writer_RGB->SetFileName( "z.png" );
>
>    filter_extract_RGB->SetInput( reader_RGB->GetOutput() );
>    writer_RGB->SetInput( filter_extract_RGB->GetOutput() );
>
>     try
>     {
>     writer_RGB->Update();
>     }
>   catch( itk::ExceptionObject & err )
>     {
>     std::cerr << "ExceptionObject caught !" << std::endl;
>     std::cerr << err << std::endl;
>     }
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110630/9133cb6c/attachment.htm>


More information about the Insight-users mailing list