<div dir="ltr"><p class=""><span lang="EN-US">Hello everyone,</span></p>

<p class="" align="left"><span lang="EN-US">I do a registration example in ITK,it
is &ldquo;ImageRegistration1.cxx&rdquo;.But I want to use &ldquo;itkParticleSwarmOptimizer.h&rdquo;
instead of &quot;itkRegularStepGradientDescentOptimizer.h&quot;.I have modified
this programming,but it has been an error.</span></p>

<p class="" align="left"><span lang="EN-US">&nbsp;</span></p>

<p class="" align="left"><span lang="EN-US">The code is as follows:</span><span lang="EN-US"></span></p><p class="" align="left"><span lang="EN-US"><br></span></p><p class="" align="left"><br></p><p class="" align="left">
#include &quot;itkImageRegistrationMethod.h&quot;</p><p class="" align="left">#include &quot;itkTranslationTransform.h&quot;</p><p class="" align="left">#include &quot;itkMeanSquaresImageToImageMetric.h&quot;</p><p class="" align="left">
#include &quot;itkParticleSwarmOptimizer.h&quot;</p><p class="" align="left">// Software Guide : EndCodeSnippet</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">#include &quot;itkImageFileReader.h&quot;</p>
<p class="" align="left">#include &quot;itkImageFileWriter.h&quot;</p><p class="" align="left"><br></p><p class="" align="left">#include &quot;itkResampleImageFilter.h&quot;</p><p class="" align="left">#include &quot;itkCastImageFilter.h&quot;</p>
<p class="" align="left">#include &quot;itkRescaleIntensityImageFilter.h&quot;</p><p class="" align="left">#include &quot;itkSubtractImageFilter.h&quot;</p><p class="" align="left"><br></p><p class="" align="left"><br></p>
<p class="" align="left"><br></p><p class="" align="left">class CommandIterationUpdate : public itk::Command</p><p class="" align="left">{</p><p class="" align="left">public:</p><p class="" align="left">&nbsp; typedef &nbsp;CommandIterationUpdate &nbsp; Self;</p>
<p class="" align="left">&nbsp; typedef &nbsp;itk::Command &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Superclass;</p><p class="" align="left">&nbsp; typedef itk::SmartPointer&lt;Self&gt; &nbsp;Pointer;</p><p class="" align="left">&nbsp; itkNewMacro( Self );</p><p class="" align="left">
<br></p><p class="" align="left">protected:</p><p class="" align="left">&nbsp; CommandIterationUpdate() {};</p><p class="" align="left"><br></p><p class="" align="left">public:</p><p class="" align="left"><br></p><p class="" align="left">
&nbsp; typedef itk::ParticleSwarmOptimizer &nbsp; &nbsp; OptimizerType;</p><p class="" align="left">&nbsp; typedef const OptimizerType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *OptimizerPointer;</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; void Execute(itk::Object *caller, const itk::EventObject &amp; event)</p>
<p class="" align="left">&nbsp; {</p><p class="" align="left">&nbsp; &nbsp; Execute( (const itk::Object *)caller, event);</p><p class="" align="left">&nbsp; }</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; void Execute(const itk::Object * object, const itk::EventObject &amp; event)</p>
<p class="" align="left">&nbsp; {</p><p class="" align="left">&nbsp; &nbsp; OptimizerPointer optimizer =</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dynamic_cast&lt; OptimizerPointer &gt;( object );</p><p class="" align="left">
<br></p><p class="" align="left">&nbsp; &nbsp; if( ! itk::IterationEvent().CheckEvent( &amp;event ) )</p><p class="" align="left">&nbsp; &nbsp; &nbsp; {</p><p class="" align="left">&nbsp; &nbsp; &nbsp; return;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; }</p><p class="" align="left">
<br></p><p class="" align="left">&nbsp; &nbsp; //std::cout &lt;&lt; optimizer-&gt;GetMaximalNumberOfIterations () &lt;&lt; &quot; = &quot;;</p><p class="" align="left">&nbsp; &nbsp; std::cout &lt;&lt; optimizer-&gt;GetValue() &lt;&lt; &quot; : &quot;;</p>
<p class="" align="left">&nbsp; &nbsp; std::cout &lt;&lt; optimizer-&gt;GetCurrentPosition() &lt;&lt; std::endl;</p><p class="" align="left">&nbsp; }</p><p class="" align="left"><br></p><p class="" align="left">};</p><p class="" align="left">
<br></p><p class="" align="left"><br></p><p class="" align="left">int main( int argc, char *argv[] )</p><p class="" align="left">{</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; const &nbsp; &nbsp;unsigned int &nbsp; &nbsp;Dimension = 2;</p>
<p class="" align="left">&nbsp; typedef &nbsp;float &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PixelType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt; &nbsp;FixedImageType;</p><p class="" align="left">&nbsp; typedef itk::Image&lt; PixelType, Dimension &gt; &nbsp;MovingImageType;</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::TranslationTransform&lt; double, Dimension &gt; TransformType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::ParticleSwarmOptimizer &nbsp; &nbsp; &nbsp; OptimizerType;</p>
<p class="" align="left">&nbsp; static OptimizerType::RandomVariateGeneratorType::IntegerType seedOffset = 0;</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; typedef itk::MeanSquaresImageToImageMetric&lt;</p><p class="" align="left">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MovingImageType &gt; &nbsp; &nbsp;MetricType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk:: LinearInterpolateImageFunction&lt;</p>
<p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MovingImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&gt; &nbsp; &nbsp;InterpolatorType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">
&nbsp; typedef itk::ImageRegistrationMethod&lt;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MovingImageType &gt; &nbsp; &nbsp;RegistrationType;</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; MetricType::Pointer &nbsp; &nbsp; &nbsp; &nbsp; metric &nbsp; &nbsp; &nbsp; &nbsp;= MetricType::New();</p><p class="" align="left">&nbsp; TransformType::Pointer &nbsp; &nbsp; &nbsp;transform &nbsp; &nbsp; = TransformType::New();</p><p class="" align="left">
&nbsp; OptimizerType::Pointer &nbsp; &nbsp; &nbsp;optimizer &nbsp; &nbsp; = OptimizerType::New();</p><p class="" align="left">&nbsp; InterpolatorType::Pointer &nbsp; interpolator &nbsp;= InterpolatorType::New();</p><p class="" align="left">&nbsp; RegistrationType::Pointer &nbsp; registration &nbsp;= RegistrationType::New();</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; registration-&gt;SetMetric( &nbsp; &nbsp; &nbsp; &nbsp;metric &nbsp; &nbsp; &nbsp; &nbsp;);</p><p class="" align="left">&nbsp; registration-&gt;SetOptimizer( &nbsp; &nbsp; optimizer &nbsp; &nbsp; );</p><p class="" align="left">&nbsp; registration-&gt;SetTransform( &nbsp; &nbsp; transform &nbsp; &nbsp; );</p>
<p class="" align="left">&nbsp; registration-&gt;SetInterpolator( &nbsp;interpolator &nbsp;);</p><p class="" align="left">&nbsp; // Software Guide : EndCodeSnippet</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">
&nbsp; typedef itk::ImageFileReader&lt; FixedImageType &nbsp;&gt; FixedImageReaderType;</p><p class="" align="left">&nbsp; typedef itk::ImageFileReader&lt; MovingImageType &gt; MovingImageReaderType;</p><p class="" align="left">&nbsp; FixedImageReaderType::Pointer &nbsp;fixedImageReader &nbsp;= FixedImageReaderType::New();</p>
<p class="" align="left">&nbsp; MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; fixedImageReader-&gt;SetFileName( &nbsp;&quot;BrainProtonDensitySliceBorder20.png&quot; );</p>
<p class="" align="left">&nbsp; movingImageReader-&gt;SetFileName( &quot;BrainProtonDensitySliceShifted13x17y.png&quot; );</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">
&nbsp; registration-&gt;SetFixedImage( &nbsp; &nbsp;fixedImageReader-&gt;GetOutput() &nbsp; &nbsp;);</p><p class="" align="left">&nbsp; registration-&gt;SetMovingImage( &nbsp; movingImageReader-&gt;GetOutput() &nbsp; );</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">
&nbsp; fixedImageReader-&gt;Update();</p><p class="" align="left">&nbsp; registration-&gt;SetFixedImageRegion(</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fixedImageReader-&gt;GetOutput()-&gt;GetBufferedRegion() );</p><p class="" align="left">
&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef RegistrationType::ParametersType ParametersType;</p><p class="" align="left">&nbsp; ParametersType initialParameters( transform-&gt;GetNumberOfParameters() );</p><p class="" align="left">
<br></p><p class="" align="left">&nbsp; initialParameters[0] = 0.0; &nbsp;// Initial offset in mm along X</p><p class="" align="left">&nbsp; initialParameters[1] = 0.0; &nbsp;// Initial offset in mm along Y</p><p class="" align="left"><br></p>
<p class="" align="left">&nbsp; registration-&gt;SetInitialTransformParameters( initialParameters );</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">
&nbsp; optimizer-&gt;UseSeedOn();</p><p class="" align="left">&nbsp; optimizer-&gt;SetSeed(8775070 + seedOffset++);</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; OptimizerType::ParameterBoundsType bounds;</p><p class="" align="left">
&nbsp; bounds.push_back( std::make_pair( 0, 1 ) );</p><p class="" align="left">&nbsp; optimizer-&gt;SetParameterBounds( bounds );</p><p class="" align="left">&nbsp; optimizer-&gt;SetNumberOfParticles( 10 );//numberOfParticles</p><p class="" align="left">
&nbsp; optimizer-&gt;SetMaximalNumberOfIterations( 100 );//maxIterations</p><p class="" align="left">&nbsp; optimizer-&gt;SetParametersConvergenceTolerance( 0.1,transform-&gt;GetNumberOfParameters() );//1ˇ˘xTolerance</p><p class="" align="left">
&nbsp; optimizer-&gt;SetFunctionConvergenceTolerance( 0.001 );//fTolerance</p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();</p>
<p class="" align="left">&nbsp; optimizer-&gt;AddObserver( itk::IterationEvent(), observer );</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; try</p>
<p class="" align="left">&nbsp; &nbsp; {</p><p class="" align="left">&nbsp; &nbsp; registration-&gt;Update();</p><p class="" align="left"><span class="" style="white-space:pre">        </span>std::cout &lt;&lt; &quot;Optimizer stop condition: &quot;</p>
<p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; registration-&gt;GetOptimizer()-&gt;GetStopConditionDescription()</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; std::endl;</p><p class="" align="left">&nbsp; &nbsp; }</p><p class="" align="left">
&nbsp; catch( itk::ExceptionObject &amp; err )</p><p class="" align="left">&nbsp; &nbsp; {</p><p class="" align="left">&nbsp; &nbsp; std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;</p><p class="" align="left">&nbsp; &nbsp; std::cerr &lt;&lt; err &lt;&lt; std::endl;</p>
<p class="" align="left">&nbsp; &nbsp; return EXIT_FAILURE;</p><p class="" align="left">&nbsp; &nbsp; }</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; ParametersType finalParameters = registration-&gt;GetLastTransformParameters();</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; const double TranslationAlongX = finalParameters[0];</p><p class="" align="left">&nbsp; const double TranslationAlongY = finalParameters[1];</p><p class="" align="left">
&nbsp;&nbsp;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; const double bestValue = optimizer-&gt;GetValue();</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; std::cout &lt;&lt; &quot;Result = &quot; &lt;&lt; std::endl;</p>
<p class="" align="left">&nbsp; std::cout &lt;&lt; &quot; Translation X = &quot; &lt;&lt; TranslationAlongX &nbsp;&lt;&lt; std::endl;</p><p class="" align="left">&nbsp; std::cout &lt;&lt; &quot; Translation Y = &quot; &lt;&lt; TranslationAlongY &nbsp;&lt;&lt; std::endl;</p>
<p class="" align="left">&nbsp; //std::cout &lt;&lt; &quot; Iterations &nbsp; &nbsp;= &quot; &lt;&lt; numberOfIterations &lt;&lt; std::endl;</p><p class="" align="left">&nbsp; std::cout &lt;&lt; &quot; Metric value &nbsp;= &quot; &lt;&lt; bestValue &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt; std::endl;</p>
<p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::ResampleImageFilter&lt;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MovingImageType,</p>
<p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType &gt; &nbsp; &nbsp;ResampleFilterType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; ResampleFilterType::Pointer resampler = ResampleFilterType::New();</p>
<p class="" align="left">&nbsp; resampler-&gt;SetInput( movingImageReader-&gt;GetOutput() );</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; resampler-&gt;SetTransform( registration-&gt;GetOutput()-&gt;Get() );</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();</p><p class="" align="left">&nbsp; resampler-&gt;SetSize( fixedImage-&gt;GetLargestPossibleRegion().GetSize() );</p>
<p class="" align="left">&nbsp; resampler-&gt;SetOutputOrigin( &nbsp;fixedImage-&gt;GetOrigin() );</p><p class="" align="left">&nbsp; resampler-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );</p><p class="" align="left">&nbsp; resampler-&gt;SetOutputDirection( fixedImage-&gt;GetDirection() );</p>
<p class="" align="left">&nbsp; resampler-&gt;SetDefaultPixelValue( 100 );</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef unsigned char OutputPixelType;</p><p class="" align="left">&nbsp; typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;</p>
<p class="" align="left">&nbsp; typedef itk::CastImageFilter&lt;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputImageType &gt; CastFilterType;</p><p class="" align="left">
&nbsp; typedef itk::ImageFileWriter&lt; OutputImageType &gt; &nbsp;WriterType;</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; WriterType::Pointer &nbsp; &nbsp; &nbsp;writer = &nbsp;WriterType::New();</p><p class="" align="left">&nbsp; CastFilterType::Pointer &nbsp;caster = &nbsp;CastFilterType::New();</p>
<p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp; writer-&gt;SetFileName( &quot;output.png&quot; );</p><p class="" align="left"><br></p><p class="" align="left">
<br></p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; caster-&gt;SetInput( resampler-&gt;GetOutput() );</p><p class="" align="left">&nbsp; writer-&gt;SetInput( caster-&gt;GetOutput() &nbsp; );</p><p class="" align="left">
&nbsp; writer-&gt;Update();</p><p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::SubtractImageFilter&lt;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType &gt; DifferenceFilterType;</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; DifferenceFilterType::Pointer difference = DifferenceFilterType::New();</p>
<p class="" align="left"><br></p><p class="" align="left">&nbsp; difference-&gt;SetInput1( fixedImageReader-&gt;GetOutput() );</p><p class="" align="left">&nbsp; difference-&gt;SetInput2( resampler-&gt;GetOutput() );</p><p class="" align="left">
&nbsp;&nbsp;</p><p class="" align="left">&nbsp; typedef itk::RescaleIntensityImageFilter&lt;</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedImageType,</p><p class="" align="left">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputImageType &gt; &nbsp; RescalerType;</p>
<p class="" align="left"><br></p><p class="" align="left">&nbsp; RescalerType::Pointer intensityRescaler = RescalerType::New();</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; intensityRescaler-&gt;SetInput( difference-&gt;GetOutput() );</p>
<p class="" align="left">&nbsp; intensityRescaler-&gt;SetOutputMinimum( &nbsp; 0 );</p><p class="" align="left">&nbsp; intensityRescaler-&gt;SetOutputMaximum( 255 );</p><p class="" align="left"><br></p><p class="" align="left">&nbsp; resampler-&gt;SetDefaultPixelValue( 1 );</p>
<p class="" align="left">&nbsp;&nbsp;</p><p class="" align="left">&nbsp; WriterType::Pointer writer2 = WriterType::New();</p><p class="" align="left">&nbsp; writer2-&gt;SetInput( intensityRescaler-&gt;GetOutput() );</p><p class="" align="left">
&nbsp; // Software Guide : EndCodeSnippet</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp; /*if( argc &gt; 4 )</p><p class="" align="left">&nbsp; &nbsp; {*/</p><p class="" align="left">&nbsp; &nbsp; writer2-&gt;SetFileName( &quot;differenceAfter.png&quot; );</p>
<p class="" align="left">&nbsp; &nbsp; writer2-&gt;Update();</p><p class="" align="left">&nbsp; &nbsp; /*}*/</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p>
<p class="" align="left">&nbsp; TransformType::Pointer identityTransform = TransformType::New();</p><p class="" align="left">&nbsp; identityTransform-&gt;SetIdentity();</p><p class="" align="left">&nbsp; resampler-&gt;SetTransform( identityTransform );</p>
<p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp; /*if( argc &gt; 5 )</p><p class="" align="left">&nbsp; &nbsp; {*/</p><p class="" align="left">&nbsp; &nbsp; writer2-&gt;SetFileName( &quot;differenceBefor.png&quot; );</p>
<p class="" align="left">&nbsp; &nbsp; writer2-&gt;Update();</p><p class="" align="left">&nbsp; &nbsp; /*}*/</p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp;&nbsp;</p>
<p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">&nbsp; return EXIT_SUCCESS;</p><p class="" align="left">}</p><p class="" align="left"><span lang="EN-US"></span></p><p class="" align="left">
<br></p><p class="" align="left"><br></p><p class="" align="left">But an error been caught ,when you run it.The error information is as follow:</p><p class="" align="left">Location:&ldquo;void _thiscall itk::ParticleSwarmOptimizerBase::validateSettings&lt;vod&gt;&rdquo;</p>
<p class="" align="left">File:D:\..\itkParticleSwarmOptimizerBase.cxx</p><p class="" align="left">Line:360</p><p class="" align="left">Description:itk::ERROR:ParticleSwarmOptimizer&lt;02A022C8&gt;:cost function and parameter bounds dimensions mismatch</p>
<p class="" align="left"><br></p><p class="" align="left"><br></p><p class="" align="left">Please give some help............................</p></div>