[Insight-users] problem in using itkGeodesicActiveContourLevelSetImageFilter for 3D image

john smith mkitkinsightuser at gmail.com
Thu Jun 9 13:46:26 EDT 2011


Hello,

I am trying to run itkGeodesicActiveContourLevelSetImageFilter to a 3D
volume and then extract a slice using the ExtractImageFilter.Considering the
pipeline, first I need to set a reader , then the filter GAC, then the
extract image filter and finally a writer to get a 2D png image. To set the
input region of the ExtractImageFilter I think that I need to update the
thresholder firstly (according with the theory of itk manual). But when I
debugging I get an excetion (in the highligted point of my code). Could
somebody help me? What I am doning wrong in the code or in the pipeline that
I am using?


ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();

  thresholder->SetLowerThreshold( -1000.0 );
  thresholder->SetUpperThreshold(     0.0 );

  thresholder->SetOutsideValue(  0  );
  thresholder->SetInsideValue(  255 );


  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileName.toStdString());


  SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();

  GradientFilterType::Pointer  gradientMagnitude =
GradientFilterType::New();

  SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();

  sigmoid->SetOutputMinimum(  0.0  );
  sigmoid->SetOutputMaximum(  1.0  );


   FastMarchingFilterType::Pointer  fastMarching =
FastMarchingFilterType::New();

   GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
                                     GeodesicActiveContourFilterType::New();

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

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


  const double propagationScaling =
ui->doubleSpinBox_propagationScaling->value();
  geodesicActiveContour->SetPropagationScaling( propagationScaling );
  geodesicActiveContour->SetCurvatureScaling( 1.0 );
  geodesicActiveContour->SetAdvectionScaling( 1.0 );


  geodesicActiveContour->SetMaximumRMSError( 0.02 );
  geodesicActiveContour->SetNumberOfIterations( 800 );


  smoothing->SetInput( reader->GetOutput() );
  gradientMagnitude->SetInput( smoothing->GetOutput() );
  sigmoid->SetInput( gradientMagnitude->GetOutput() );

  geodesicActiveContour->SetInput(  fastMarching->GetOutput() );
  geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );

  thresholder->SetInput( geodesicActiveContour->GetOutput() );

  //////////////////////////
  thresholder->Update();
  InputImageType::RegionType inputRegion =
           thresholder->GetOutput()->GetLargestPossibleRegion();

  InputImageType::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 coordinate
  size[2] = 0;

   InputImageType::IndexType start = inputRegion.GetIndex();
 // const unsigned int sliceNumber = 90;
  ui->verticalScrollBar_z->setRange(0,size_z-1);
  unsigned int sliceNumber = ui->verticalScrollBar_z->value();
  start[2] = sliceNumber;
 // ui->verticalScrollBar_z->setValue(sliceNumber);


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

  filter_extract->SetExtractionRegion( desiredRegion );

  ////////////////////////////

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


  smoothing->SetTimeStep( 0.0625 );
  smoothing->SetNumberOfIterations(  5 );
  smoothing->SetConductanceParameter( 9.0 );

  const double sigma = ui->doubleSpinBox_sigma->value();
  gradientMagnitude->SetSigma(  sigma  );

  const double alpha =  ui->doubleSpinBox_alpha->value();
  const double beta  =  ui->doubleSpinBox_beta->value();
  sigmoid->SetAlpha( alpha );
  sigmoid->SetBeta(  beta  );


  NodeContainer::Pointer seeds = NodeContainer::New();

  InputImageType::IndexType  seedPosition;

  seedPosition[0] = ui->doubleSpinBox_seed_x->value();
  seedPosition[1] = ui->doubleSpinBox_seed_y->value();
  seedPosition[2] = ui->doubleSpinBox_seed_z->value();

  const double initialDistance =
ui->doubleSpinBox_initial_distance->value();

  NodeType node;

  const double seedValue = - initialDistance;

  node.SetValue( seedValue );
  node.SetIndex( seedPosition );


  seeds->Initialize();
  seeds->InsertElement( 0, node );

   fastMarching->SetTrialPoints(  seeds  );

   fastMarching->SetSpeedConstant( 1.0 );

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


More information about the Insight-users mailing list