[Insight-users] problem using extract image filter

john smith mkitkinsightuser at gmail.com
Fri Jun 10 08:41:53 EDT 2011


Hello to all,

I am reading a 3D image using a reader, then I rescale the volume using
RescaleIntensityImageFilter, then extract a subregion from the rescaled
volume and finally I extract slices from this subregion. But every time I am
daclare the input region for the extract  slice Image Filter then I get an
exception I hope that someone could help me.

Thanks in advance

  typedef float               InputPixelType;
  typedef unsigned char       OutputPixelType;
  const   unsigned int        Dimension = 3;

  typedef itk::Image< InputPixelType,  Dimension >    InputImageType;
  typedef itk::Image< OutputPixelType, Dimension >    OutputImageType;

  typedef itk::ImageFileReader< InputImageType  >  ReaderType;

   typedef itk::RegionOfInterestImageFilter< OutputImageType,
                                            OutputImageType >
FilterType_region;

  typedef itk::RescaleIntensityImageFilter<
                                 InputImageType,
                                  OutputImageType >    FilterType_rescale;
  typedef  unsigned char        InputPixelType_extract;
  typedef unsigned char        OutputPixelType_extract;
  typedef itk::Image< InputPixelType_extract,  3 >
InputImageType_extract;
  typedef itk::Image< OutputPixelType_extract, 2 >
OutputImageType_extract;
   typedef itk::ExtractImageFilter< InputImageType_extract,
OutputImageType_extract > FilterType_extract;
///////////////////////////////////////////////////
/////////////////////////////////////


   FilterType_rescale::Pointer filter_rescale = FilterType_rescale::New();
       filter_rescale->SetOutputMinimum(   0 );
       filter_rescale->SetOutputMaximum( value_norm );

//////extract region filter
       FilterType_region::Pointer filter_region = FilterType_region::New();
        OutputImageType::IndexType start_region;
        start_region[0] = ui->doubleSpinBox_start_x->value();
        start_region[1] = ui->doubleSpinBox_start_y->value();
        start_region[2] = ui->doubleSpinBox_start_z->value();

        OutputImageType::SizeType size_region;
        size_region[0] = ui->doubleSpinBox_size_x->value();
        size_region[1] = ui->doubleSpinBox_size_y->value();
        size_region[2] = ui->doubleSpinBox_size_z->value();

        OutputImageType::RegionType desiredRegion_region;
        desiredRegion_region.SetSize(  size_region  );
        desiredRegion_region.SetIndex( start_region );

        filter_region->SetRegionOfInterest( desiredRegion_region );

        ReaderType::Pointer reader = ReaderType::New();

        reader->SetFileName( fileName.toStdString()  );

        filter_rescale->SetInput( reader->GetOutput() );
        filter_region->SetInput( filter_rescale->GetOutput() );

        filter_region->Update();

      /////////////////////
  FilterType_extract::Pointer filter_extract = FilterType_extract::New();

  OutputImageType::RegionType inputRegion =
          filter_region->GetOutput()->GetLargestPossibleRegion();

  OutputImageType::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;

   OutputImageType::IndexType start = inputRegion.GetIndex();

  ui->verticalScrollBar_z->setRange(0,size_z-1);
  unsigned int sliceNumber = ui->verticalScrollBar_z->value();
  start[2] = sliceNumber;


  OutputImageType::RegionType desiredRegion;
  desiredRegion.SetSize( size );
  desiredRegion.SetIndex( start );

  filter_extract->SetExtractionRegion( desiredRegion );

     WriterType::Pointer writer = WriterType::New();
    writer->SetFileName( "z.png" );

  filter_extract->SetInput( filter_region->GetOutput() );
   writer->SetInput( filter_extract->GetOutput() );

    try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110610/38474926/attachment.htm>


More information about the Insight-users mailing list