#include "itkConfigure.h"
#ifndef ITK_USE_FFTWD
#error "This program needs FFTWD to work."
#endif
{
public:
typedef CommandIterationUpdate
Self;
itkNewMacro( CommandIterationUpdate );
protected:
CommandIterationUpdate() {};
InternalImageType,
InternalImageType,
DisplacementFieldType,
public:
{
}
{
const RegistrationFilterType * filter = static_cast< const RegistrationFilterType * >( object );
if( !(itk::IterationEvent().CheckEvent( &event )) )
{
return;
}
std::cout << filter->GetMetric() << std::endl;
}
};
int main( int argc, char *argv[] )
{
if( argc < 4 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " fixedImageFile movingImageFile ";
std::cerr << " outputImageFile " << std::endl;
return EXIT_FAILURE;
}
typedef short PixelType;
FixedImageReaderType::Pointer fixedImageReader =
FixedImageReaderType::New();
MovingImageReaderType::Pointer movingImageReader =
MovingImageReaderType::New();
fixedImageReader->SetFileName( argv[1] );
movingImageReader->SetFileName( argv[2] );
typedef float InternalPixelType;
InternalImageType > FixedImageCasterType;
InternalImageType > MovingImageCasterType;
FixedImageCasterType::Pointer fixedImageCaster =
FixedImageCasterType::New();
MovingImageCasterType::Pointer movingImageCaster =
MovingImageCasterType::New();
fixedImageCaster->SetInput( fixedImageReader->GetOutput() );
movingImageCaster->SetInput( movingImageReader->GetOutput() );
InternalImageType,
InternalImageType > MatchingFilterType;
MatchingFilterType::Pointer matcher = MatchingFilterType::New();
matcher->SetInput( movingImageCaster->GetOutput() );
matcher->SetReferenceImage( fixedImageCaster->GetOutput() );
matcher->SetNumberOfHistogramLevels( 1024 );
matcher->SetNumberOfMatchPoints( 7 );
matcher->ThresholdAtMeanIntensityOn();
InternalImageType,
InternalImageType,
DisplacementFieldType,
RegistrationFilterType::Pointer filter = RegistrationFilterType::New();
filter->SetTimeStep( 1 );
filter->SetConstraintWeight( 0.1 );
CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
filter->AddObserver( itk::IterationEvent(), observer );
InternalImageType,
InternalImageType,
DisplacementFieldType > MultiResRegistrationFilterType;
MultiResRegistrationFilterType::Pointer multires = MultiResRegistrationFilterType::New();
multires->SetRegistrationFilter( filter );
multires->SetNumberOfLevels( 3 );
multires->SetFixedImage( fixedImageCaster->GetOutput() );
multires->SetMovingImage( matcher->GetOutput() );
unsigned int nIterations[4] = { 10, 20, 50, 50 };
multires->SetNumberOfIterations( nIterations );
multires->Update();
MovingImageType,
MovingImageType,
DisplacementFieldType > WarperType;
MovingImageType,
double > InterpolatorType;
WarperType::Pointer warper = WarperType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
warper->SetInput( movingImageReader->GetOutput() );
warper->SetInterpolator( interpolator );
warper->SetOutputSpacing( fixedImage->GetSpacing() );
warper->SetOutputOrigin( fixedImage->GetOrigin() );
warper->SetOutputDirection( fixedImage->GetDirection() );
warper->SetDisplacementField( multires->GetOutput() );
typedef unsigned short OutputPixelType;
MovingImageType,
OutputImageType > CastFilterType;
WriterType::Pointer writer = WriterType::New();
CastFilterType::Pointer caster = CastFilterType::New();
writer->SetFileName( argv[3] );
caster->SetInput( warper->GetOutput() );
writer->SetInput( caster->GetOutput() );
writer->Update();
if( argc > 4 )
{
FieldWriterType::Pointer fieldWriter = FieldWriterType::New();
fieldWriter->SetFileName( argv[4] );
fieldWriter->SetInput( multires->GetOutput() );
try
{
fieldWriter->Update();
}
{
}
}
return EXIT_SUCCESS;
}