[Insight-users] Reg. Growing: no region is being segmented

Carin Hartelius carha341 at student.liu.se
Mon Aug 1 09:02:23 EDT 2005


Dear ITK users,

I'm working on an application for segmentation of orthopedic data as a 
part of my degree. I'm using ITK to perform region growing 
segmentation and then visualize the result with VTK. 

I'm a student and new to programming, C++ as well as ITK, so please 
bare with me. 

I pick seed point and set parameters in a wxWindow GUI and send a 
vtkDataSet to my region growing class. I set all parameters with Set-
functions. The application is running but the volume I get from the 
segmentation is always empty. It has correct dimension and bounds but 
is empty. I have tried settings that I know will produce a volume on a 
particular volume but still nothing is being segmented.

It did produce a segmented region at first but was unstable and only 
segmented one type of tissue, not bone which is what I want. Now, 
nothing at all is possible to segment and I can't seem to track back 
why. I really don't know where to turn, so I'm humbly asking for your 
help. My code is included below.

Many thanks in advance!
Best regards,
Carin Hartelius

________________________________________ 

#include "mmoDoITKRegionGrowing.h"

//--------itk---------------
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkVTKImageIO.h"

#include "itkConnectedThresholdImageFilter.h"
#include "itkIsolatedConnectedImageFilter.h"
#include "itkNeighborhoodConnectedImageFilter.h"
#include "itkConfidenceConnectedImageFilter.h"
#include "itkIsolatedConnectedImageFilter.h"

#include "itkCurvatureFlowImageFilter.h"
#include "itkCastImageFilter.h"

//--------vtk and itk connections-------------
#include "itkImageToVTKImageFilter.h"
#include "itkVTKImageToImageFilter.h"

//----------vtk---------------------
#include "vtkImageCast.h" 
#include "vtkImageData.h"


mmoDoITKRegionGrowing::mmoDoITKRegionGrowing(vtkDataSet * dataset, int 
m_idTab) 
{
  m_DatasetToSegment = dataset;   
  m_SegmentedDataset = NULL;
  m_IdRegionGrowing = m_idTab;
  m_AllSeedX = m_AllSeedY = m_AllSeedZ = 0; 
   m_CurvFlowNoIterations = 5;
   m_CurvFlowTimeStep = 0.125;
   m_AllLowerThreshold = 0;  
   m_AllUpperThreshold = 0;
   m_IsoSeedX2 = m_IsoSeedY2 = m_IsoSeedZ2 = 0; 
   m_IsoUpper = 0;
   m_IsoLower = 0;
   m_NeighInitialRadiusX = m_NeighInitialRadiusY = 
m_NeighInitialRadiusZ = 2; 
   m_ConfRadius = 2;
   m_ConfNoIter = 1;
   m_ConfMultiplier = 2.5;
   m_AllReplaceValue = 255;
 }
//---------------------------------------------------------------------
-------
mmoDoITKRegionGrowing::~mmoDoITKRegionGrowing( ) 
//---------------------------------------------------------------------
-------
{
   m_SegmentedDataset->Delete();
}


//---------------------------------------------------------------------
-------
void mmoDoITKRegionGrowing::runSegmentation()
//---------------------------------------------------------------------
-------
{

//-----------------------------------------------
//			       seed points
//-----------------------------------------------
  internalImageType::IndexType  seedIndex1;
  seedIndex1[0] = m_AllSeedX;
  seedIndex1[1] = m_AllSeedY;
	seedIndex1[2] = m_AllSeedZ;

  //set seed point 2
  internalImageType::IndexType  seedIndex2;
  seedIndex2[0] = m_IsoSeedX2;
  seedIndex2[1] = m_IsoSeedY2;
	seedIndex2[2] = m_IsoSeedZ2;
//_______________________________________________


//-----------------------------------------------
//        vtk cast filter 
//-----------------------------------------------
vtkImageCast * vtkImageToChar = vtkImageCast::New();
vtkImageToChar->SetOutputScalarTypeToUnsignedChar ();
//_______________________________________________



//-----------------------------------------------
//	VTK to ITK Filter (on ITK side)
//-----------------------------------------------
typedef itk::VTKImageToImageFilter< inputImageType > 
vtk2ITKConnectorType;	
vtk2ITKConnectorType::Pointer pVTKitkConnector = 
vtk2ITKConnectorType::New();
//_______________________________________________



//-----------------------------------------------
//	Caster Filter - type cast to float 
//-----------------------------------------------
typedef  itk::CastImageFilter<inputImageType, internalImageType>  
InputCastFilterType;
InputCastFilterType::Pointer pCasterInput = InputCastFilterType::New();
//_______________________________________________



//-----------------------------------------------
// Curvature Flow Image Filter 
//-----------------------------------------------
typedef itk::CurvatureFlowImageFilter<internalImageType, 
internalImageType> 
		CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer pSmoothing = 
CurvatureFlowImageFilterType::New();
pSmoothing->SetNumberOfIterations( m_CurvFlowNoIterations );
pSmoothing->SetTimeStep( m_CurvFlowTimeStep );
//_______________________________________________


//-----------------------------------------------
//	  Connected Threshold Segmentation Filter
//-----------------------------------------------
typedef itk::ConnectedThresholdImageFilter<internalImageType, 
		segmentedImageType>  ConThresholdFilterType;
ConThresholdFilterType::Pointer pConThresholdFilter = 
ConThresholdFilterType::New();
    pConThresholdFilter->SetLower( m_AllLowerThreshold );
    pConThresholdFilter->SetUpper( m_AllUpperThreshold );
    pConThresholdFilter->SetReplaceValue( m_AllReplaceValue );
	  pConThresholdFilter->SetSeed( seedIndex1 );
//_________________________________________________

    

//-----------------------------------------------
//	  Isolated Connected Threshold Segmentation Filter
//-----------------------------------------------
typedef itk::IsolatedConnectedImageFilter<internalImageType, 
		segmentedImageType>  IsoConThresholdFilterType;
IsoConThresholdFilterType::Pointer pIsoConThresholdFilter = 
IsoConThresholdFilterType::New();
    pIsoConThresholdFilter->SetLower( m_IsoLower );
    pIsoConThresholdFilter->SetUpper( m_IsoUpper );
    pIsoConThresholdFilter->SetReplaceValue( m_AllReplaceValue );
  	pIsoConThresholdFilter->SetSeed1( seedIndex1 );
    pIsoConThresholdFilter->SetSeed2( seedIndex2 );
//_________________________________________________


//-----------------------------------------------
// Neighborhood Connected Threshold Segmentation Filter
//-----------------------------------------------
typedef itk::NeighborhoodConnectedImageFilter<internalImageType, 
		segmentedImageType>  NeighConThresholdFilterType;
NeighConThresholdFilterType::Pointer pNeighConThresholdFilter =    
NeighConThresholdFilterType::New();
    pNeighConThresholdFilter->SetLower( m_AllLowerThreshold );
    pNeighConThresholdFilter->SetUpper( m_AllUpperThreshold );
    internalImageType::SizeType radius;
    radius[0] = m_NeighInitialRadiusX; // two pixels along X
    radius[1] = m_NeighInitialRadiusY; // two pixels along Y
    radius[2] = m_NeighInitialRadiusZ; // two pixels along Z
    pNeighConThresholdFilter->SetRadius( radius );
    pNeighConThresholdFilter->SetReplaceValue( m_AllReplaceValue );
    pNeighConThresholdFilter->SetSeed( seedIndex1 );
//_________________________________________________


//-----------------------------------------------
//	  Confidence Connected Threshold Segmentation Filter
//-----------------------------------------------
     typedef itk::ConfidenceConnectedImageFilter<internalImageType, 
		segmentedImageType>  ConfConThresholdFilterType;
    ConfConThresholdFilterType::Pointer pConfConThresholdFilter = 
ConfConThresholdFilterType::New();
    pConfConThresholdFilter->SetMultiplier( m_ConfMultiplier );
    pConfConThresholdFilter->SetInitialNeighborhoodRadius( 
m_ConfRadius );
    pConfConThresholdFilter->SetReplaceValue( m_AllReplaceValue );
    pConfConThresholdFilter->SetSeed( seedIndex1 );
//_________________________________________________


//-----------------------------------------------
//			        itk writer
//-----------------------------------------------
	
	typedef itk::ImageFileWriter< segmentedImageType > 
FileWriterType;
	typedef itk::VTKImageIO                   ImageIOType;  
	FileWriterType::Pointer pFileWriter = FileWriterType::New();
	ImageIOType::Pointer    pvtkIO      = ImageIOType::New();
  pFileWriter->SetFileName( "filename.vtk" );
      pvtkIO->SetFileTypeToASCII();
    pFileWriter->SetImageIO( pvtkIO ); 

//_______________________________________________


//-----------------------------------------------
//			ITK to VTK Filter
//-----------------------------------------------
    typedef itk::ImageToVTKImageFilter< segmentedImageType > 
itkToVTKConnectorType;
    itkToVTKConnectorType::Pointer pITKvtkConnector = 
itkToVTKConnectorType::New();
//_______________________________________________
	


//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
//	                 PIPELINES
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''


//-----------------------------------------------
//			PIPELINE - VTK  
//-----------------------------------------------
//converts from vtkDataSet to vtkImageData
vtkImageToChar->SetInput( (vtkImageData *)m_DatasetToSegment );

//-----------------------------------------------
//	PIPELINE - VTK to ITK connection (ITK filter) 
//-----------------------------------------------
	
pVTKitkConnector->SetInput( vtkImageToChar->GetOutput() );
  try
  {
	pVTKitkConnector->GetImporter()->Update();
  }
  catch( ... )
  {
    std::cout << "ExceptionObject caught !" << std::endl;
    return;
  }

//_______________________________________________


//-----------------------------------------------
//			ITK PIPELINE
//-----------------------------------------------
pCasterInput->SetInput( pVTKitkConnector->GetImporter()->GetOutput() );
pSmoothing->SetInput( pCasterInput->GetOutput() );
	    
  switch(m_IdRegionGrowing) 
    {
    case 0:
   pConThresholdFilter->SetInput( pSmoothing->GetOutput() );
  pFileWriter->SetInput( (segmentedImageType *)pConThresholdFilter-
>GetOutput() );
  pITKvtkConnector->SetInput( pConThresholdFilter->GetOutput() );
    break;

    case 1:
   pIsoConThresholdFilter->SetInput( pSmoothing->GetOutput() );
  pFileWriter->SetInput( (segmentedImageType *)pIsoConThresholdFilter-
>GetOutput() );
   pITKvtkConnector->SetInput( pIsoConThresholdFilter->GetOutput() );
    break;

    case 2:
    pNeighConThresholdFilter->SetInput( pSmoothing->GetOutput() );
  pFileWriter->SetInput( (segmentedImageType *)
pNeighConThresholdFilter->GetOutput() );
    pITKvtkConnector->SetInput( pNeighConThresholdFilter->GetOutput
() );
    break;

    case 3:
   pConfConThresholdFilter->SetInput( pSmoothing->GetOutput() );
pFileWriter->SetInput( (segmentedImageType *) pConfConThresholdFilter-
>GetOutput() );
    pITKvtkConnector->SetInput( pConfConThresholdFilter->GetOutput() );
    break;
    }
  try
		{
	 pFileWriter->Update();
	 	}
    catch( ... ) 
    {
    return;
	  }

  pITKvtkConnector->GetImporter()->SetDataScalarTypeToUnsignedChar();  
//__________________________________________________

	
//-----------------------------------------------
//	Pointer to pipeline output
//-----------------------------------------------    
m_SegmentedDataset = vtkImageData::New();
try
{
pITKvtkConnector->Update();
}
catch( ... ) 
{
  return;
}

((vtkImageData *) pITKvtkConnector->GetOutput())->Update();
m_SegmentedDataset->DeepCopy((vtkImageData *) pITKvtkConnector-
>GetOutput());  


//-----------------------------------------------
//	 Re-allocate memory 
//------------------ -----------------------------    
vtkImageToChar->Delete();
	}


//---------------------------------------------------------------------
-------
vtkImageData* mmoDoITKRegionGrowing::GetSegmentation()
//---------------------------------------------------------------------
-------
{
  return m_SegmentedDataset;
}

____________________________ 
____________________________

parts of the h-file:
  vtkDataSet * m_DatasetToSegment;
  vtkImageData * m_SegmentedDataset;
  typedef unsigned char		inputPixelType;
  typedef float				internalPixelType;
  typedef unsigned char		segmentedPixelType;
  enum { imageDimension = 3 };
  typedef itk::Image< inputPixelType, imageDimension >	inputImageType;
  typedef itk::Image< internalPixelType, imageDimension>
	internalImageType;
  typedef itk::Image< segmentedPixelType, imageDimension>
	segmentedImageType;

  unsigned int m_CurvFlowNoIterations;
  float m_CurvFlowTimeStep;
    internalPixelType m_AllSeedX; 
    internalPixelType m_AllSeedY; 
    internalPixelType m_AllSeedZ;
    unsigned int m_IdRegionGrowing;
    int m_AllLowerThreshold;  
    int m_AllUpperThreshold;
    internalPixelType m_IsoSeedX2; 
    internalPixelType m_IsoSeedY2;
    internalPixelType m_IsoSeedZ2;
 internalPixelType m_IsoUpper;
  internalPixelType m_IsoLower;
    unsigned int m_NeighInitialRadiusX;
    unsigned int m_NeighInitialRadiusY;
    unsigned int m_NeighInitialRadiusZ;
    unsigned int m_ConfRadius;
   unsigned int m_ConfNoIter;
  	int m_ConfMultiplier;
  unsigned int m_AllReplaceValue;

Then I use a bunch of Set functions to set all parameters



More information about the Insight-users mailing list