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