[Insight-users] RGB Registration
Dan Mueller
dan.muel at gmail.com
Wed Nov 19 11:07:57 EST 2008
Hi Leidy,
It looks like you are missing a reference to ITKNumerics. Try adding
it to the TARGET_LINK_LIBRARIES of your CMakeList.txt file:
TARGET_LINK_LIBRARIES( ITKCommon ... ITKNumerics )
Hope this helps.
Cheers, Dan
2008/11/19 Leidy Paola Dorado Muñoz <doradoleidypao at gmail.com>:
>
> Hello all,
> I am performing registration of RGB images. Initially,RGB Images are
> converted into gray-scale images and with the gray-scale images the
> registration is performed, but I get some errors.
> Could somebody help me with this problem?
> The code is based on example ImageRegistration1. The following is my code:
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #include "itkRGBPixel.h"
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkVectorResampleImageFilter.h"
> #include "itkTranslationTransform.h"
> #include "itkVectorLinearInterpolateImageFunction.h"
> #include "itkRGBToLuminanceImageFilter.h"
> #include "itkResampleImageFilter.h"
> #include "itkLinearInterpolateImageFunction.h"
>
> #include "itkImageRegistrationMethod.h"
> #include "itkMeanSquaresImageToImageMetric.h"
> #include "itkRegularStepGradientDescentOptimizer.h"
> #include "itkCastImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkSubtractImageFilter.h"
>
> class CommandIterationUpdate : public itk::Command
> {
> public:
> typedef CommandIterationUpdate Self;
> typedef itk::Command Superclass;
> typedef itk::SmartPointer<Self> Pointer;
> itkNewMacro( Self );
>
> protected:
> CommandIterationUpdate() {};
>
> public:
>
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef const OptimizerType *OptimizerPointer;
>
> void Execute(itk::Object *caller, const itk::EventObject & event)
> {
> Execute( (const itk::Object *)caller, event);
> }
>
> void Execute(const itk::Object * object, const itk::EventObject & event)
> {
> OptimizerPointer optimizer =
> dynamic_cast< OptimizerPointer >( object );
>
> if( ! itk::IterationEvent().CheckEvent( &event ) )
> {
> return;
> }
>
> std::cout << optimizer->GetCurrentIteration() << " = ";
> std::cout << optimizer->GetValue() << " : ";
> std::cout << optimizer->GetCurrentPosition() << 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 [differenceImageAfter]";
> std::cerr << "[differenceImageBefore]" << std::endl;
> return EXIT_FAILURE;
> }
>
> typedef itk::RGBPixel<unsigned char> PixelType;
> typedef itk::Image< PixelType, 2 > FixedImageType;
> typedef itk::Image< PixelType, 2 > MovingImageType;
> typedef itk::Image< unsigned char,2 > GrayFixedImageType;
> typedef itk::Image< unsigned char,2 > GrayMovingImageType;
>
> typedef itk::TranslationTransform< double, 2 > TransformType;
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef
> itk::MeanSquaresImageToImageMetric<GrayFixedImageType,GrayMovingImageType >
> MetricType;
> typedef itk::LinearInterpolateImageFunction<GrayMovingImageType, double>
> InterpolatorType;
> typedef
> itk::ImageRegistrationMethod<GrayFixedImageType,GrayMovingImageType >
> RegistrationType;
>
> 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();
> 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();
> fixedImageReader->SetFileName("Things_new.jpg");
> movingImageReader ->SetFileName("Things_new_2.jpg");
>
> typedef itk::RGBToLuminanceImageFilter< FixedImageType,GrayFixedImageType
>> FixedGrayType;
> typedef itk::RGBToLuminanceImageFilter<
> MovingImageType,GrayMovingImageType > MovingGrayType;
>
> FixedGrayType::Pointer grayfilter1 = FixedGrayType::New();
> grayfilter1->SetInput( fixedImageReader->GetOutput() );
>
> MovingGrayType::Pointer grayfilter2 = MovingGrayType::New();
> grayfilter2->SetInput( movingImageReader->GetOutput() );
>
> registration->SetFixedImage(grayfilter1->GetOutput());
> registration->SetMovingImage(grayfilter2->GetOutput());
>
> typedef RegistrationType::ParametersType ParametersType;
> ParametersType initialParameters( transform->GetNumberOfParameters() );
>
> initialParameters[0] = 0.0; // Initial offset in mm along X
> initialParameters[1] = 0.0; // Initial offset in mm along Y
>
> registration->SetInitialTransformParameters(initialParameters);
>
> optimizer->SetMaximumStepLength( 4.00 );
> optimizer->SetMinimumStepLength( 0.01 );
> optimizer->SetNumberOfIterations( 200 );
>
> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
> optimizer->AddObserver( itk::IterationEvent(), observer );
>
> try
> {
> registration->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return EXIT_FAILURE;
> }
>
> ParametersType finalParameters =
> registration->GetLastTransformParameters();
> const double TranslationAlongX = finalParameters[0];
> const double TranslationAlongY = finalParameters[1];
> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
> const double bestValue = optimizer->GetValue();
>
> std::cout << "Result = " << std::endl;
> std::cout << " Translation X = " << TranslationAlongX << std::endl;
> std::cout << " Translation Y = " << TranslationAlongY << std::endl;
> std::cout << " Iterations = " << numberOfIterations << std::endl;
> std::cout << " Metric value = " << bestValue << std::endl;
>
> typedef itk::ResampleImageFilter< GrayFixedImageType,GrayMovingImageType >
> ResampleFilterType;
> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
> resampler->SetInput(grayfilter2->GetOutput() ); // Imagen sensada en gris
> resampler->SetTransform(registration->GetOutput()->Get() ); //parametros
> dados por la registracion
>
> GrayFixedImageType::Pointer fixedImage = grayfilter1->GetOutput();
> //consigue parametros adicionales
> resampler->SetSize(fixedImage->GetLargestPossibleRegion().GetSize());
> //desde la iamgen de referencia
> resampler->SetOutputOrigin(fixedImage->GetOrigin()); // pero en escala
> de gris
> resampler->SetOutputSpacing(fixedImage->GetSpacing());
> resampler->SetOutputDirection(fixedImage->GetDirection());
> resampler->SetDefaultPixelValue(100);
>
> //typedef itk::LinearInterpolateImageFunction <GrayFixedImageType, double>
> InterpolatorType;
> //InterpolatorType::Pointer interpolator = InterpolatorType::New();
>
> //typedef itk::IdentityTransform < double, 2 > TransformType;
> //TransformType::Pointer transform=TransformType::New();
>
> // resampler ->SetInterpolator(interpolator);
> // resampler ->SetTransform(transform);
>
> resampler ->Update();
>
> typedef unsigned char GrayOutputPixelType;
> typedef itk::Image< GrayOutputPixelType, 2 > GrayOutputImageType;
> typedef itk::CastImageFilter<GrayFixedImageType,GrayOutputImageType >
> CastFilterType;
> typedef itk::ImageFileWriter< GrayOutputImageType > WriterType;
>
> WriterType::Pointer writer = WriterType::New();
> CastFilterType::Pointer caster = CastFilterType::New();
> writer->SetFileName( "ImageRegistered.jpg" );
>
> caster->SetInput(resampler->GetOutput());
> writer->SetInput(caster->GetOutput());
> writer->Update();
>
> return EXIT_SUCCESS;
> }
>
> And the errors are:
>
> 1>------ Build started: Project: RGBRegistration, Configuration: Debug x64
> ------
> 1>Compiling...
> 1>RGBRegistration.cxx
> 1>Compiling manifest to resources...
> 1>Linking...
> 1> Creating library Debug\RGBRegistration.lib and object
> Debug\RGBRegistration.exp
> 1>RGBRegistration.obj : error LNK2019: unresolved external symbol
> "protected: __cdecl
> itk::RegularStepGradientDescentBaseOptimizer::RegularStepGradientDescentBaseOptimizer(void)"
> (??0RegularStepGradientDescentBaseOptimizer at itk@@IEAA at XZ) referenced in
> function "protected: __cdecl
> itk::RegularStepGradientDescentOptimizer::RegularStepGradientDescentOptimizer(void)"
> (??0RegularStepGradientDescentOptimizer at itk@@IEAA at XZ)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl
> itk::RegularStepGradientDescentBaseOptimizer::PrintSelf(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> itk::Indent)const "
> (?PrintSelf at RegularStepGradientDescentBaseOptimizer@itk@@MEBAXAEAV?$basic_ostream at DU?$char_traits at D@std@@@std@@VIndent at 2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public:
> virtual void __cdecl itk::Optimizer::SetInitialPosition(class
> itk::Array<double> const &)"
> (?SetInitialPosition at Optimizer@itk@@UEAAXAEBV?$Array at N@2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public:
> virtual void __cdecl
> itk::RegularStepGradientDescentBaseOptimizer::StartOptimization(void)"
> (?StartOptimization at RegularStepGradientDescentBaseOptimizer@itk@@UEAAXXZ)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl itk::Optimizer::SetCurrentPosition(class
> itk::Array<double> const &)"
> (?SetCurrentPosition at Optimizer@itk@@MEAAXAEBV?$Array at N@2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public:
> virtual void __cdecl
> itk::SingleValuedNonLinearOptimizer::SetCostFunction(class
> itk::SingleValuedCostFunction *)"
> (?SetCostFunction at SingleValuedNonLinearOptimizer@itk@@UEAAXPEAVSingleValuedCostFunction at 2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl
> itk::RegularStepGradientDescentBaseOptimizer::AdvanceOneStep(void)"
> (?AdvanceOneStep at RegularStepGradientDescentBaseOptimizer@itk@@MEAAXXZ)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl
> itk::RegularStepGradientDescentOptimizer::StepAlongGradient(double,class
> itk::Array<double> const &)"
> (?StepAlongGradient at RegularStepGradientDescentOptimizer@itk@@MEAAXNAEBV?$Array at N@2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl
> itk::SingleValuedNonLinearOptimizer::PrintSelf(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> itk::Indent)const "
> (?PrintSelf at SingleValuedNonLinearOptimizer@itk@@MEBAXAEAV?$basic_ostream at DU?$char_traits at D@std@@@std@@VIndent at 2@@Z)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl itk::Optimizer::PrintSelf(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> itk::Indent)const "
> (?PrintSelf at Optimizer@itk@@MEBAXAEAV?$basic_ostream at DU?$char_traits at D@std@@@std@@VIndent at 2@@Z)
> 1>RGBRegistration.obj : error LNK2019: unresolved external symbol
> "protected: __cdecl itk::Optimizer::Optimizer(void)"
> (??0Optimizer at itk@@IEAA at XZ) referenced in function "public: static class
> itk::SmartPointer<class itk::Optimizer> __cdecl itk::Optimizer::New(void)"
> (?New at Optimizer@itk@@SA?AV?$SmartPointer at VOptimizer@itk@@@2 at XZ)
> 1>RGBRegistration.obj : error LNK2019: unresolved external symbol
> "protected: __cdecl
> itk::SingleValuedNonLinearOptimizer::SingleValuedNonLinearOptimizer(void)"
> (??0SingleValuedNonLinearOptimizer at itk@@IEAA at XZ) referenced in function
> "public: static class itk::SmartPointer<class
> itk::SingleValuedNonLinearOptimizer> __cdecl
> itk::SingleValuedNonLinearOptimizer::New(void)"
> (?New at SingleValuedNonLinearOptimizer@itk@@SA?AV?$SmartPointer at VSingleValuedNonLinearOptimizer@itk@@@2 at XZ)
> 1>RGBRegistration.obj : error LNK2001: unresolved external symbol
> "protected: virtual void __cdecl itk::CostFunction::PrintSelf(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> itk::Indent)const "
> (?PrintSelf at CostFunction@itk@@MEBAXAEAV?$basic_ostream at DU?$char_traits at D@std@@@std@@VIndent at 2@@Z)
> 1>Debug\RGBRegistration.exe : fatal error LNK1120: 13 unresolved externals
> 1>Build log was saved at
> "file://w:\Registration_Review\bin\RGBRegistration\RGBRegistration.dir\Debug\BuildLog.htm"
> 1>RGBRegistration - 14 error(s), 0 warning(s)
> 2>------ Build started: Project: ALL_BUILD, Configuration: Debug x64 ------
> 2>"Build all projects"
> 2>Build log was saved at
> "file://w:\Registration_Review\bin\RGBRegistration\ALL_BUILD.dir\Debug\BuildLog.htm"
> 2>ALL_BUILD - 0 error(s), 0 warning(s)
> ========== Build: 1 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
>
> --
>
> Leidy Paola Dorado-Muñoz
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list