[Insight-users] Kullback Liebler distance metric

Fab_83 Fabian_Eisa at gmx.de
Wed Mar 26 04:44:16 EDT 2008


Hi everybody,
I am trying to use the metrics provided by itk for CT registration. I have a
little problem with the
itk::KullbackLeiblerCompareHistogramImagetoImageMetric. I get the error:
"Trainings Transform is not present." I tried to fix it by using
"FormTrainingsHistogram" but it still doesn't work. 
Can sombody help me? Do you know where to find some other metric examples?

Thanks very much!

This is my code:

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"


#include "itkTranslationTransform.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkLinearInterpolateImageFunction.h"

#include "itkKullbackLeiblerCompareHistogramImageToImageMetric.h"


int main( int argc, char * argv[] )
{
  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "  fixedImage  movingImage" << std::endl;
    return EXIT_FAILURE;
    }


  const     unsigned int   Dimension = 3;
  typedef   short  PixelType;

  typedef itk::Image< PixelType, Dimension >   ImageType;

  typedef itk::ImageFileReader< ImageType >  ReaderType;

  ReaderType::Pointer fixedReader  = ReaderType::New();
  ReaderType::Pointer movingReader = ReaderType::New();

  fixedReader ->SetFileName(  argv[ 1 ] );
  movingReader->SetFileName( argv[ 2 ] );
  

  try 
    {
    fixedReader->Update();
    movingReader->Update();
	
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception catched !" << std::endl;
    std::cerr << excep << std::endl;
    }

 
   typedef itk::KullbackLeiblerCompareHistogramImageToImageMetric <
ImageType, ImageType >  DistanceType;
	
  DistanceType::Pointer distance = DistanceType::New();

  
  typedef itk::CompareHistogramImageToImageMetric < ImageType, ImageType >
CompareType;

  CompareType::Pointer compare;

//  CompareType::Pointer compare = CompareType::New();

  typedef itk::TranslationTransform< double, Dimension >  TransformType;

  TransformType::Pointer transform = TransformType::New();		// object of the
transform type

  typedef itk::LinearInterpolateImageFunction< ImageType, double > 
InterpolatorType;

  InterpolatorType::Pointer interpolator = InterpolatorType::New();	//
object of the interpolator type

  


 

  transform->SetIdentity();
 

  ImageType::ConstPointer fixedImage  = fixedReader->GetOutput();
  ImageType::ConstPointer movingImage = movingReader->GetOutput();


  
  distance->SetTransform( transform );
  distance->SetInterpolator( interpolator );

  distance->SetFixedImage(  fixedImage  );
  distance->SetMovingImage( movingImage );

  distance->SetFixedImageRegion(  fixedImage->GetBufferedRegion()  );

  //distance->FormTrainingHistogram();
   
  
 try 
    {
    
	distance->Initialize();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception catched !" << std::endl;
    std::cerr << excep << std::endl;
    return EXIT_FAILURE;
    }


  DistanceType::TransformParametersType correlationdisplacement( Dimension
);
  
  const int rangex = 0;
  const int rangey = 0;
  const int rangez = 0;

  for( int dx = -rangex; dx <= rangex; dx++ )
    {
    for( int dy = -rangey; dy <= rangey; dy++ )
      {
		  for (int dz = -rangez; dz<=rangez; dz++)
		  {
			  correlationdisplacement[0]= dx;
			  correlationdisplacement[1]=dy;
			  correlationdisplacement[2]=dz;
			  const double correlationvalue = distance->GetValue(
correlationdisplacement );
			 
			 std::cout << dx << "   "  << dy << "   " << dz << "	" <<
correlationvalue << std::endl;
		  }
      }
    }



  return EXIT_SUCCESS;
}





-- 
View this message in context: http://www.nabble.com/Kullback-Liebler-distance-metric-tp16273571p16273571.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list