<br clear="all"><b>Hello all,<br>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. <br>
Could somebody help me with this problem?<br>The code is based on example ImageRegistration1. The following is my code:</b><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#include "itkRGBPixel.h"<br>
#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkVectorResampleImageFilter.h"<br>#include "itkTranslationTransform.h"<br>
#include "itkVectorLinearInterpolateImageFunction.h"<br>#include "itkRGBToLuminanceImageFilter.h"<br>#include "itkResampleImageFilter.h"<br>#include "itkLinearInterpolateImageFunction.h" <br>
<br>#include "itkImageRegistrationMethod.h"<br>#include "itkMeanSquaresImageToImageMetric.h"<br>#include "itkRegularStepGradientDescentOptimizer.h" <br>#include "itkCastImageFilter.h"<br>
#include "itkRescaleIntensityImageFilter.h"<br>#include "itkSubtractImageFilter.h"<br><br>class CommandIterationUpdate : public itk::Command <br>{<br>public:<br> typedef CommandIterationUpdate Self;<br>
typedef itk::Command Superclass;<br> typedef itk::SmartPointer<Self> Pointer;<br> itkNewMacro( Self );<br><br>protected:<br> CommandIterationUpdate() {};<br><br>public:<br><br> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;<br>
typedef const OptimizerType *OptimizerPointer;<br><br>void Execute(itk::Object *caller, const itk::EventObject & event)<br> {<br> Execute( (const itk::Object *)caller, event);<br> }<br><br>
void Execute(const itk::Object * object, const itk::EventObject & event)<br> {<br> OptimizerPointer optimizer = <br> dynamic_cast< OptimizerPointer >( object );<br><br> if( ! itk::IterationEvent().CheckEvent( &event ) )<br>
{<br> return;<br> }<br><br> std::cout << optimizer->GetCurrentIteration() << " = ";<br> std::cout << optimizer->GetValue() << " : ";<br> std::cout << optimizer->GetCurrentPosition() << std::endl;<br>
}<br> <br>};<br><br>int main( int argc , char ** argv[])<br>{<br> if( argc < 4 )<br> {<br> std::cerr << "Missing Parameters " << std::endl;<br> std::cerr << "Usage: " << argv[0];<br>
std::cerr << " fixedImageFile movingImageFile ";<br> std::cerr << "outputImagefile [differenceImageAfter]";<br> std::cerr << "[differenceImageBefore]" << std::endl;<br>
return EXIT_FAILURE;<br> }<br><br> typedef itk::RGBPixel<unsigned char> PixelType;<br> typedef itk::Image< PixelType, 2 > FixedImageType;<br> typedef itk::Image< PixelType, 2 > MovingImageType;<br>
typedef itk::Image< unsigned char,2 > GrayFixedImageType;<br> typedef itk::Image< unsigned char,2 > GrayMovingImageType;<br><br> typedef itk::TranslationTransform< double, 2 > TransformType;<br> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;<br>
typedef itk::MeanSquaresImageToImageMetric<GrayFixedImageType,GrayMovingImageType > MetricType;<br> typedef itk::LinearInterpolateImageFunction<GrayMovingImageType, double> InterpolatorType;<br> typedef itk::ImageRegistrationMethod<GrayFixedImageType,GrayMovingImageType > RegistrationType;<br>
<br> MetricType::Pointer metric = MetricType::New();<br> TransformType::Pointer transform = TransformType::New();<br> OptimizerType::Pointer optimizer = OptimizerType::New();<br> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
RegistrationType::Pointer registration = RegistrationType::New();<br> registration->SetMetric(metric);<br> registration->SetOptimizer(optimizer);<br> registration->SetTransform(transform);<br> registration->SetInterpolator(interpolator);<br>
<br> typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;<br> typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;<br> FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();<br>
MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();<br> fixedImageReader->SetFileName("Things_new.jpg");<br> movingImageReader ->SetFileName("Things_new_2.jpg");<br>
<br> typedef itk::RGBToLuminanceImageFilter< FixedImageType,GrayFixedImageType > FixedGrayType;<br> typedef itk::RGBToLuminanceImageFilter< MovingImageType,GrayMovingImageType > MovingGrayType;<br><br> FixedGrayType::Pointer grayfilter1 = FixedGrayType::New();<br>
grayfilter1->SetInput( fixedImageReader->GetOutput() );<br><br> MovingGrayType::Pointer grayfilter2 = MovingGrayType::New();<br> grayfilter2->SetInput( movingImageReader->GetOutput() );<br><br> registration->SetFixedImage(grayfilter1->GetOutput());<br>
registration->SetMovingImage(grayfilter2->GetOutput());<br><br> typedef RegistrationType::ParametersType ParametersType;<br> ParametersType initialParameters( transform->GetNumberOfParameters() );<br><br> initialParameters[0] = 0.0; // Initial offset in mm along X<br>
initialParameters[1] = 0.0; // Initial offset in mm along Y<br><br> registration->SetInitialTransformParameters(initialParameters);<br> <br> optimizer->SetMaximumStepLength( 4.00 ); <br> optimizer->SetMinimumStepLength( 0.01 );<br>
optimizer->SetNumberOfIterations( 200 );<br> <br> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br> optimizer->AddObserver( itk::IterationEvent(), observer );<br> <br> try <br> { <br>
registration->Update(); <br> } <br> catch( itk::ExceptionObject & err ) <br> { <br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err << std::endl; <br>
return EXIT_FAILURE;<br> } <br><br> ParametersType finalParameters = registration->GetLastTransformParameters();<br> const double TranslationAlongX = finalParameters[0];<br> const double TranslationAlongY = finalParameters[1];<br>
const unsigned int numberOfIterations = optimizer->GetCurrentIteration();<br> const double bestValue = optimizer->GetValue();<br> <br> std::cout << "Result = " << std::endl;<br> std::cout << " Translation X = " << TranslationAlongX << std::endl;<br>
std::cout << " Translation Y = " << TranslationAlongY << std::endl;<br> std::cout << " Iterations = " << numberOfIterations << std::endl;<br> std::cout << " Metric value = " << bestValue << std::endl;<br>
<br> typedef itk::ResampleImageFilter< GrayFixedImageType,GrayMovingImageType > ResampleFilterType;<br> ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br> resampler->SetInput(grayfilter2->GetOutput() ); // Imagen sensada en gris<br>
resampler->SetTransform(registration->GetOutput()->Get() ); //parametros dados por la registracion<br> <br> GrayFixedImageType::Pointer fixedImage = grayfilter1->GetOutput(); //consigue parametros adicionales<br>
resampler->SetSize(fixedImage->GetLargestPossibleRegion().GetSize()); //desde la iamgen de referencia<br> resampler->SetOutputOrigin(fixedImage->GetOrigin()); // pero en escala de gris<br> resampler->SetOutputSpacing(fixedImage->GetSpacing());<br>
resampler->SetOutputDirection(fixedImage->GetDirection());<br> resampler->SetDefaultPixelValue(100);<br><br> //typedef itk::LinearInterpolateImageFunction <GrayFixedImageType, double> InterpolatorType;<br>
//InterpolatorType::Pointer interpolator = InterpolatorType::New();<br> <br> //typedef itk::IdentityTransform < double, 2 > TransformType; <br> //TransformType::Pointer transform=TransformType::New();<br><br> // resampler ->SetInterpolator(interpolator);<br>
// resampler ->SetTransform(transform);<br><br> resampler ->Update();<br><br> typedef unsigned char GrayOutputPixelType;<br> typedef itk::Image< GrayOutputPixelType, 2 > GrayOutputImageType; <br> typedef itk::CastImageFilter<GrayFixedImageType,GrayOutputImageType > CastFilterType;<br>
typedef itk::ImageFileWriter< GrayOutputImageType > WriterType;<br><br> WriterType::Pointer writer = WriterType::New();<br> CastFilterType::Pointer caster = CastFilterType::New();<br> writer->SetFileName( "ImageRegistered.jpg" ); <br>
<br> caster->SetInput(resampler->GetOutput()); <br> writer->SetInput(caster->GetOutput());<br> writer->Update();<br><br> return EXIT_SUCCESS;<br>}<br><br><b>And the errors are:<br><br></b>1>------ Build started: Project: RGBRegistration, Configuration: Debug x64 ------<br>
1>Compiling...<br>1>RGBRegistration.cxx<br>1>Compiling manifest to resources...<br>1>Linking...<br>1> Creating library Debug\RGBRegistration.lib and object Debug\RGBRegistration.exp<br>1>RGBRegistration.obj : error LNK2019: unresolved external symbol "protected: __cdecl itk::RegularStepGradientDescentBaseOptimizer::RegularStepGradientDescentBaseOptimizer(void)" (??0RegularStepGradientDescentBaseOptimizer@itk@@IEAA@XZ) referenced in function "protected: __cdecl itk::RegularStepGradientDescentOptimizer::RegularStepGradientDescentOptimizer(void)" (??0RegularStepGradientDescentOptimizer@itk@@IEAA@XZ)<br>
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@RegularStepGradientDescentBaseOptimizer@itk@@MEBAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@VIndent@2@@Z)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl itk::Optimizer::SetInitialPosition(class itk::Array<double> const &)" (?SetInitialPosition@Optimizer@itk@@UEAAXAEBV?$Array@N@2@@Z)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl itk::RegularStepGradientDescentBaseOptimizer::StartOptimization(void)" (?StartOptimization@RegularStepGradientDescentBaseOptimizer@itk@@UEAAXXZ)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl itk::Optimizer::SetCurrentPosition(class itk::Array<double> const &)" (?SetCurrentPosition@Optimizer@itk@@MEAAXAEBV?$Array@N@2@@Z)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl itk::SingleValuedNonLinearOptimizer::SetCostFunction(class itk::SingleValuedCostFunction *)" (?SetCostFunction@SingleValuedNonLinearOptimizer@itk@@UEAAXPEAVSingleValuedCostFunction@2@@Z)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl itk::RegularStepGradientDescentBaseOptimizer::AdvanceOneStep(void)" (?AdvanceOneStep@RegularStepGradientDescentBaseOptimizer@itk@@MEAAXXZ)<br>
1>RGBRegistration.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl itk::RegularStepGradientDescentOptimizer::StepAlongGradient(double,class itk::Array<double> const &)" (?StepAlongGradient@RegularStepGradientDescentOptimizer@itk@@MEAAXNAEBV?$Array@N@2@@Z)<br>
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@SingleValuedNonLinearOptimizer@itk@@MEBAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@VIndent@2@@Z)<br>
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@Optimizer@itk@@MEBAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@VIndent@2@@Z)<br>
1>RGBRegistration.obj : error LNK2019: unresolved external symbol "protected: __cdecl itk::Optimizer::Optimizer(void)" (??0Optimizer@itk@@IEAA@XZ) referenced in function "public: static class itk::SmartPointer<class itk::Optimizer> __cdecl itk::Optimizer::New(void)" (?New@Optimizer@itk@@SA?AV?$SmartPointer@VOptimizer@itk@@@2@XZ)<br>
1>RGBRegistration.obj : error LNK2019: unresolved external symbol "protected: __cdecl itk::SingleValuedNonLinearOptimizer::SingleValuedNonLinearOptimizer(void)" (??0SingleValuedNonLinearOptimizer@itk@@IEAA@XZ) referenced in function "public: static class itk::SmartPointer<class itk::SingleValuedNonLinearOptimizer> __cdecl itk::SingleValuedNonLinearOptimizer::New(void)" (?New@SingleValuedNonLinearOptimizer@itk@@SA?AV?$SmartPointer@VSingleValuedNonLinearOptimizer@itk@@@2@XZ)<br>
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@CostFunction@itk@@MEBAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@VIndent@2@@Z)<br>
1>Debug\RGBRegistration.exe : fatal error LNK1120: 13 unresolved externals<br>1>Build log was saved at "file://w:\Registration_Review\bin\RGBRegistration\RGBRegistration.dir\Debug\BuildLog.htm"<br>1>RGBRegistration - 14 error(s), 0 warning(s)<br>
2>------ Build started: Project: ALL_BUILD, Configuration: Debug x64 ------<br>2>"Build all projects"<br>2>Build log was saved at "file://w:\Registration_Review\bin\RGBRegistration\ALL_BUILD.dir\Debug\BuildLog.htm"<br>
2>ALL_BUILD - 0 error(s), 0 warning(s)<br>========== Build: 1 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========<b><br><br></b>-- <br><br>Leidy Paola Dorado-Muņoz<br><br>