[Insight-users] Problem using filters
Rob Bijman
lambikjes at hotmail.com
Tue Jun 1 04:27:26 EDT 2004
Dear ITK users,
I have a problem using filters inside my program.
For my program I use two pictures to registrate the movement between the
two.
Now I want to use filters for the pictures to change the pixel intensities
(Especially the Binary Tresholdfilter to turn the pixels into black (0) and
white (255)), but the filters don't do anything at all. Maybe that's because
the filter doesn't work for two images at the same time? Can somebody tell
me what I am doing wrong? (There were no errors when running)
The program parameters from a part of my program are listed below.
With kind regards,
Rob Bijman
if (m_Affine2 == TRUE)
{
const unsigned int Dimension = 2;
typedef float PixelType;
//////////////
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, 2 > InputImageType;
///////////
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
////////////
typedef itk::Image< PixelType, Dimension > FixedImageType;
typedef itk::Image< PixelType, Dimension > MovingImageType;
//typedef itk::Image< PixelType, Dimension > OutputImageType;
typedef itk::CenteredAffineTransform< double, Dimension > TransformType;
typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
typedef itk::MeanSquaresImageToImageMetric<
FixedImageType,
MovingImageType > MetricType;
typedef itk:: LinearInterpolateImageFunction<
MovingImageType,
double > InterpolatorType;
typedef itk::ImageRegistrationMethod<
FixedImageType,
MovingImageType > RegistrationType;
//////////////////////////////////////////////////////////////////////////////////
typedef itk::BinaryThresholdImageFilter< //
InputImageType, OutputImageType > FilterType; //
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< InputImageType > WriterType;
//////////////////////////////////////////////////////////////////////////////////
MetricType::Pointer metric = MetricType::New();
TransformType::Pointer transform = TransformType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
RegistrationType::Pointer registration = RegistrationType::New();
///////////////////////////////////////////////////
ReaderType::Pointer reader = ReaderType::New();//
FilterType::Pointer filter = FilterType::New();//
///////////////////////////////////////////////////
registration->SetMetric( metric );
registration->SetOptimizer( optimizer );
registration->SetTransform( transform );
registration->SetInterpolator( interpolator );
typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
FixedImageReaderType::Pointer fixedImageReader =
FixedImageReaderType::New();
MovingImageReaderType::Pointer movingImageReader =
MovingImageReaderType::New();
////
try
{
////////////////////////////////////////////
filter->SetInput( reader->GetOutput() );//
filter->SetOutsideValue(0); //
filter->SetInsideValue(255); //
filter->SetLowerThreshold( 10 ); //
filter->SetUpperThreshold( 255); //
filter->Update(); //
////////////////////////////////////////////
}
catch(...)
{
m_sTekst = "Verkeerde parameters";
}
////
fixedImageReader->SetFileName( m_sRef );
movingImageReader->SetFileName( m_sTar );
registration->SetFixedImage( fixedImageReader->GetOutput() );
registration->SetMovingImage( movingImageReader->GetOutput() );
fixedImageReader->Update();
movingImageReader->Update();
m_sTekst = "Work in Progress";
UpdateData(FALSE);
registration->SetFixedImageRegion(
fixedImageReader->GetOutput()->GetBufferedRegion() );
typedef itk::CenteredTransformInitializer<
TransformType,
FixedImageType,
MovingImageType >
TransformInitializerType;
TransformInitializerType::Pointer initializer =
TransformInitializerType::New();
initializer->SetTransform( transform );
initializer->SetFixedImage( fixedImageReader->GetOutput() );
initializer->SetMovingImage( movingImageReader->GetOutput() );
initializer->MomentsOn();
initializer->InitializeTransform();
registration->SetInitialTransformParameters( transform->GetParameters() );
double translationScale = 1.0 / 5000.0;
typedef OptimizerType::ScalesType OptimizerScalesType;
OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );
optimizerScales[0] = 1.0;
optimizerScales[1] = 1.0;
optimizerScales[2] = 1.0;
optimizerScales[3] = 1.0;
optimizerScales[4] = translationScale;
optimizerScales[5] = translationScale;
optimizerScales[6] = translationScale;
optimizerScales[7] = translationScale;
optimizer->SetScales( optimizerScales );
double steplength = 4;
unsigned int maxNumberOfIterations = m_dMaxIter;
optimizer->SetMaximumStepLength( steplength );
optimizer->SetMinimumStepLength( 0.001 );
optimizer->SetNumberOfIterations( maxNumberOfIterations );
optimizer->MinimizeOn();
try
{
registration->StartRegistration();
}
catch(...)
{
m_sTekst= "Er gaat iets niet goed";
}
OptimizerType::ParametersType finalParameters =
registration->GetLastTransformParameters();
const double finalRot = finalParameters[2];
const double finalRotationCenterX = finalParameters[4];
const double finalRotationCenterY = finalParameters[5];
const double finalTranslationX = finalParameters[6];
const double finalTranslationY = finalParameters[7];
const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
const double bestValue = optimizer->GetValue();
//const double finalMetric = metric->GetValue(); // eventueel kan het ook
zoals in ImageRegistration9.cxx met resample
///////////////// Einde ITK gedeelte
m_dTransX = 0; //Translatie doet hier niet mee;
m_dTransY = 0; //Translatie doet hier niet mee;
m_dRot = 58.63*finalRot; //Van radialen naar graden;
m_dOpt = 0;
m_dIter = numberOfIterations; //Aantal Iteraties
_________________________________________________________________
Play online games with your friends with MSN Messenger
http://messenger.msn.nl/
More information about the Insight-users
mailing list