<div dir="ltr">Massinissa,<div><br></div><div>The fact that you are compiling for Debug, explains why the code is taking a long time to run.</div><div><br></div><div>Please give it a try at compiling for Release, that can easily make a difference of 10X or 20X</div>
<div>in the execution time. Most of the C++ template optimizations that ITK relies on, only happen</div><div>when you compile for Release.</div><div><br></div><div>Once you run it in Release mode, please share the output of the Command observer class.</div>
<div>This should help illuminate the progression of the transform and the metric values.</div><div><br></div><div>    Thanks</div><div><br></div><div>        Luis</div><div><br></div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Dec 13, 2013 at 2:59 PM, Massinissa Bandou <span dir="ltr">&lt;<a href="mailto:Massinissa.Bandou@usherbrooke.ca" target="_blank">Massinissa.Bandou@usherbrooke.ca</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for replying Mr Luis!!!!<br>
<br>
I&#39;m using win7 x64 and I&#39;m compiling on debug mode.<br>
<br>
The *source* image is from a series of dicom<br>
format: float<br>
image dimension: 120 x 120 x 137<br>
voxel dimension: 0.5 x 0.5 x 0.596756<br>
<br>
The *target* image is a raw file.<br>
format: short<br>
image dimension: 256 x 256 x 256<br>
voxel dimension: 0.308 x 0.308 x 0.308<br>
<br>
I decided to register 2 same images and use the same code as<br>
*Registration/ImageRegistration8.cxx*<br>
but I got the following error:<br>
<br>
&lt;<a href="http://itk-users.7.n7.nabble.com/file/n32985/error.png" target="_blank">http://itk-users.7.n7.nabble.com/file/n32985/error.png</a>&gt;<br>
<br>
and my code is:<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
<br>
vtkSmartPointer&lt;vtkImageReader&gt; imagetarget =<br>
vtkSmartPointer&lt;vtkImageReader&gt;::New();<br>
<br>
imagetarget-&gt;SetFileName(&quot;C:/Users/Massi/Desktop/Engineering/IRM_CT_FIDUCIALS/CT_(130802_m_FDGF18_004ct)/image/CT_volume.raw&quot;);<br>
        imagetarget-&gt;SetFileDimensionality(3);<br>
        imagetarget-&gt;SetDataExtent(0,511,0,511,0,511);<br>
        imagetarget-&gt;SetDataSpacing(0.154,0.154,0.154);<br>
        imagetarget-&gt;SetDataByteOrderToLittleEndian();<br>
        imagetarget-&gt;SetDataScalarTypeToShort();<br>
        imagetarget-&gt;Update();<br>
<br>
        vtkSmartPointer&lt;vtkImageReslice&gt; resliceMyTargetImage =<br>
vtkSmartPointer&lt;vtkImageReslice&gt;::New();<br>
        resliceMyTargetImage -&gt;SetInputConnection(imagetarget-&gt;GetOutputPort());<br>
        resliceMyTargetImage-&gt;SetOutputExtent(0,255, 0,255, 0,255);<br>
        double p[3];<br>
        for(unsigned int i=0;i&lt;3;i++){<br>
                p[i] = (512 * 0.154) / 256;<br>
        }<br>
        resliceMyTargetImage-&gt;SetOutputSpacing(p[0],p[1],p[2]);<br>
        resliceMyTargetImage-&gt;SetOutputDimensionality(3);<br>
        resliceMyTargetImage-&gt;SetInterpolationModeToCubic();<br>
        resliceMyTargetImage-&gt;AutoCropOutputOn();<br>
        resliceMyTargetImage-&gt;SetResliceAxesOrigin(0,0,0);<br>
        resliceMyTargetImage-&gt;Update();<br>
<br>
        vtkSmartPointer&lt;vtkDICOMImageReader&gt; imagesource =<br>
vtkSmartPointer&lt;vtkDICOMImageReader&gt;::New();<br>
<br>
imagesource-&gt;SetDirectoryName(&quot;C:/Users/Massi/Downloads/M016_Labpet8_20130425/T_6&quot;);<br>
        imagesource-&gt;Update();<br>
<br>
<br>
        typedef itk::Image&lt;float, 3&gt; FixedImageType;<br>
        typedef itk::Image&lt;short, 3&gt; MovingImageType;<br>
<br>
        /*transform vtk image to itk image*/<br>
        typedef itk::VTKImageToImageFilter&lt;FixedImageType&gt; FixedImageReaderType;<br>
        typedef itk::VTKImageToImageFilter&lt;MovingImageType&gt; MovingImageReaderType;<br>
<br>
    FixedImageReaderType::Pointer fixedImageReader =<br>
FixedImageReaderType::New();<br>
        MovingImageReaderType::Pointer movingImageReader =<br>
MovingImageReaderType::New();<br>
        fixedImageReader-&gt;SetInput(imagesource-&gt;GetOutput());  // source<br>
        movingImageReader-&gt;SetInput(resliceMyTargetImage-&gt;GetOutput()); //target<br>
<br>
        typedef itk::VersorRigid3DTransform&lt; double &gt; TransformType;<br>
        typedef itk::VersorRigid3DTransformOptimizer<br>
OptimizerType;<br>
        typedef itk::MeanSquaresImageToImageMetric&lt; FixedImageType, MovingImageType<br>
&gt; MetricType;<br>
        typedef itk:: LinearInterpolateImageFunction&lt; MovingImageType, double &gt;<br>
InterpolatorType;<br>
        typedef itk::ImageRegistrationMethod&lt; FixedImageType, MovingImageType &gt;<br>
RegistrationType;<br>
<div class="im"><br>
        MetricType::Pointer         metric        = MetricType::New();<br>
</div><div class="im">        OptimizerType::Pointer      optimizer     = OptimizerType::New();<br>
        InterpolatorType::Pointer   interpolator  = InterpolatorType::New();<br>
        RegistrationType::Pointer   registration  = RegistrationType::New();<br>
</div>        registration-&gt;SetMetric(        metric        );<br>
        registration-&gt;SetOptimizer(     optimizer     );<br>
        registration-&gt;SetInterpolator(  interpolator  );<br>
<div class="im"><br>
        TransformType::Pointer  transform = TransformType::New();<br>
</div>        registration-&gt;SetTransform( transform );<br>
<br>
        fixedImageReader-&gt;Update();<br>
<br>
registration-&gt;SetFixedImageRegion(fixedImageReader-&gt;GetOutput()-&gt;GetBufferedRegion());<br>
<br>
        typedef<br>
itk::CenteredTransformInitializer&lt;TransformType,FixedImageType,MovingImageType&gt;<br>
TransformInitializerType;<br>
        TransformInitializerType::Pointer initializer =<br>
TransformInitializerType::New();<br>
<br>
        initializer-&gt;SetTransform(transform);<br>
        initializer-&gt;SetFixedImage(fixedImageReader-&gt;GetOutput());<br>
        initializer-&gt;SetMovingImage(movingImageReader-&gt;GetOutput());<br>
        initializer-&gt;MomentsOn();<br>
        initializer-&gt;InitializeTransform();<br>
<br>
        typedef TransformType::VersorType  VersorType;<br>
        typedef VersorType::VectorType     VectorType;<br>
        VersorType     rotation;<br>
        VectorType     axis;<br>
        axis[0] = 0.0;<br>
        axis[1] = 0.0;<br>
        axis[2] = 1.0;<br>
        const double angle = 0;<br>
        rotation.Set(  axis, angle  );<br>
        transform-&gt;SetRotation( rotation );<br>
<br>
        registration-&gt;SetInitialTransformParameters( transform-&gt;GetParameters() );<br>
<br>
        typedef OptimizerType::ScalesType       OptimizerScalesType;<br>
        OptimizerScalesType optimizerScales( transform-&gt;GetNumberOfParameters() );<br>
        const double translationScale = 1.0 / 1000.0;<br>
        optimizerScales[0] = 1.0;<br>
        optimizerScales[1] = 1.0;<br>
        optimizerScales[2] = 1.0;<br>
        optimizerScales[3] = translationScale;<br>
        optimizerScales[4] = translationScale;<br>
        optimizerScales[5] = translationScale;<br>
        optimizer-&gt;SetScales( optimizerScales );<br>
        optimizer-&gt;SetMaximumStepLength( 0.2000  );<br>
        optimizer-&gt;SetMinimumStepLength( 0.0001 );<br>
        optimizer-&gt;SetNumberOfIterations( 200 );<br>
<br>
        CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br>
        optimizer-&gt;AddObserver( itk::IterationEvent(), observer );<br>
<br>
        try{<br>
<div class="im">                registration-&gt;Update();<br>
                std::cout &lt;&lt; &quot;Optimizer stop condition: &quot;&lt;&lt;<br>
registration-&gt;GetOptimizer()-&gt;GetStopConditionDescription()&lt;&lt; std::endl;<br>
    }<br>
</div>        catch( itk::ExceptionObject &amp; err ){<br>
                std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;<br>
                std::cerr &lt;&lt; err &lt;&lt; std::endl;<br>
    }<br>
<br>
        OptimizerType::ParametersType finalParameters =<br>
registration-&gt;GetLastTransformParameters();<br>
        const double versorX              = finalParameters[0];<br>
        const double versorY              = finalParameters[1];<br>
        const double versorZ              = finalParameters[2];<br>
        const double finalTranslationX    = finalParameters[3];<br>
        const double finalTranslationY    = finalParameters[4];<br>
        const double finalTranslationZ    = finalParameters[5];<br>
        const unsigned int numberOfIterations = optimizer-&gt;GetCurrentIteration();<br>
        const double bestValue = optimizer-&gt;GetValue();<br>
<br>
        std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Result = &quot; &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; versor X      = &quot; &lt;&lt; versorX  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; versor Y      = &quot; &lt;&lt; versorY  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; versor Z      = &quot; &lt;&lt; versorZ  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Translation X = &quot; &lt;&lt; finalTranslationX  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Translation Y = &quot; &lt;&lt; finalTranslationY  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Translation Z = &quot; &lt;&lt; finalTranslationZ  &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Iterations    = &quot; &lt;&lt; numberOfIterations &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot; Metric value  = &quot; &lt;&lt; bestValue          &lt;&lt; std::endl;<br>
<br>
        transform-&gt;SetParameters( finalParameters );<br>
        TransformType::MatrixType matrix = transform-&gt;GetMatrix();<br>
        TransformType::OffsetType offset = transform-&gt;GetOffset();<br>
        std::cout &lt;&lt; &quot;Matrix = &quot; &lt;&lt; std::endl &lt;&lt; matrix &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot;Offset = &quot; &lt;&lt; std::endl &lt;&lt; offset &lt;&lt; std::endl;<br>
<br>
        typedef itk::ResampleImageFilter&lt; MovingImageType,FixedImageType &gt;<br>
<div class="im">ResampleFilterType;<br>
        TransformType::Pointer finalTransform = TransformType::New();<br>
</div>        finalTransform-&gt;SetCenter( transform-&gt;GetCenter() );<br>
        finalTransform-&gt;SetParameters( finalParameters );<br>
        finalTransform-&gt;SetFixedParameters( transform-&gt;GetFixedParameters() );<br>
        ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>
        resampler-&gt;SetTransform( finalTransform );<br>
        resampler-&gt;SetInput( movingImageReader-&gt;GetOutput() );<br>
        FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();<br>
        resampler-&gt;SetSize(    fixedImage-&gt;GetLargestPossibleRegion().GetSize() );<br>
        resampler-&gt;SetOutputOrigin(  fixedImage-&gt;GetOrigin() );<br>
        resampler-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<br>
        resampler-&gt;SetOutputDirection( fixedImage-&gt;GetDirection() );<br>
        resampler-&gt;SetDefaultPixelValue( 100 );<br>
<br>
        typedef unsigned char                                   OutputPixelType;<br>
        typedef itk::Image&lt; OutputPixelType, 3 &gt;                OutputImageType;<br>
        typedef itk::CastImageFilter&lt; FixedImageType, OutputImageType &gt;<br>
CastFilterType;<br>
        typedef itk::ImageFileWriter&lt; OutputImageType &gt;                 WriterType;<br>
        //WriterType::Pointer      writer =  WriterType::New();<br>
        CastFilterType::Pointer  caster =  CastFilterType::New();<br>
        //writer-&gt;SetFileName( &quot;result.raw&quot; );<br>
        caster-&gt;SetInput( resampler-&gt;GetOutput() );<br>
        //writer-&gt;SetInput( caster-&gt;GetOutput()   );<br>
        //writer-&gt;Update();<br>
<br>
        typedef<br>
itk::SubtractImageFilter&lt;FixedImageType,FixedImageType,FixedImageType &gt;<br>
DifferenceFilterType;<br>
        DifferenceFilterType::Pointer difference = DifferenceFilterType::New();<br>
        typedef itk::RescaleIntensityImageFilter&lt;FixedImageType,OutputImageType &gt;<br>
RescalerType;<br>
        RescalerType::Pointer intensityRescaler = RescalerType::New();<br>
        intensityRescaler-&gt;SetInput( difference-&gt;GetOutput() );<br>
        intensityRescaler-&gt;SetOutputMinimum(   0 );<br>
        intensityRescaler-&gt;SetOutputMaximum( 255 );<br>
        difference-&gt;SetInput1( fixedImageReader-&gt;GetOutput() );<br>
        difference-&gt;SetInput2( resampler-&gt;GetOutput() );<br>
        resampler-&gt;SetDefaultPixelValue( 1 );<br>
<br>
<br>
        /*connect to VTK*/<br>
        typedef itk::ImageToVTKImageFilter&lt;OutputImageType&gt; ConnectorType;<br>
<div class="im">        ConnectorType::Pointer connector = ConnectorType::New();<br>
</div>        connector-&gt;SetInput(caster-&gt;GetOutput());<br>
        connector-&gt;Update();<br>
<br>
        vtkSmartPointer&lt;vtkGPUVolumeRayCastMapper&gt; volumeMapper =<br>
vtkSmartPointer&lt;vtkGPUVolumeRayCastMapper&gt;::New();<br>
        volumeMapper-&gt;SetInput(connector-&gt;GetOutput());<br>
        volumeMapper-&gt;AutoAdjustSampleDistancesOff();<br>
        volumeMapper-&gt;SetBlendModeToComposite();<br>
<br>
        /********************set color &amp; opacity*******************/<br>
    vtkSmartPointer&lt;vtkVolumeProperty&gt; volumeProperty =<br>
vtkSmartPointer&lt;vtkVolumeProperty&gt;::New();<br>
    vtkSmartPointer&lt;vtkPiecewiseFunction&gt; compositeOpacity =<br>
vtkSmartPointer&lt;vtkPiecewiseFunction&gt;::New();<br>
        vtkSmartPointer&lt;vtkColorTransferFunction&gt; color =<br>
vtkSmartPointer&lt;vtkColorTransferFunction&gt;::New();<br>
<br>
<br>
compositeOpacity-&gt;AddPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[0],0.0);<br>
<br>
compositeOpacity-&gt;AddPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*3/255,0.0);<br>
<br>
compositeOpacity-&gt;AddPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*15/255,0.1);<br>
<br>
compositeOpacity-&gt;AddPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*70/255,0.2);<br>
<br>
compositeOpacity-&gt;AddPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*75/255,0.3);<br>
<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*0/255,0.0,0.0,0.0);<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*3/255,1.0,0.3,0.3);//<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*20/255,0.0,0.0,1.0);<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*50/255,0.9,0.37,0.27);<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*80.0/255,0.15,0.15,0.5);<br>
<br>
color-&gt;AddRGBPoint(connector-&gt;GetOutput()-&gt;GetScalarRange()[1]*120.0/255,1.0,1.0,1.0);<br>
<br>
                        volumeProperty-&gt;SetAmbient(0.5);<br>
                        volumeProperty-&gt;SetDiffuse(0.8);<br>
                        volumeProperty-&gt;SetSpecular(8.0);<br>
                        volumeProperty-&gt;SetInterpolationTypeToLinear();<br>
    volumeProperty-&gt;SetColor(color);<br>
        volumeProperty-&gt;SetScalarOpacity(compositeOpacity);<br>
    volumeProperty-&gt;ShadeOn();<br>
<br>
    vtkSmartPointer&lt;vtkVolume&gt; volume = vtkSmartPointer&lt;vtkVolume&gt;::New();<br>
    volume-&gt;SetMapper(volumeMapper);<br>
    volume-&gt;SetProperty(volumeProperty);<br>
<br>
        vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow =<br>
vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>
        vtkSmartPointer&lt;vtkRenderer&gt; renderer =<br>
vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
        renderWindow-&gt;AddRenderer(renderer);<br>
        renderer-&gt;AddVolume(volume);<br>
        renderer-&gt;SetBackground(0.9,0.9,0.9);<br>
        renderer-&gt;GradientBackgroundOn();<br>
        vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor =<br>
    vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);<br>
<br>
        /*Set camera position*/<br>
        renderer-&gt;GetActiveCamera()-&gt;Azimuth(30);<br>
        renderer-&gt;GetActiveCamera()-&gt;Elevation(30);<br>
        renderer-&gt;ResetCamera();<br>
          renderWindow-&gt;Render();<br>
  renderWindowInteractor-&gt;Start();<br>
<br>
        return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-users.7.n7.nabble.com/registration-using-Mutual-Information-tp32972p32985.html" target="_blank">http://itk-users.7.n7.nabble.com/registration-using-Mutual-Information-tp32972p32985.html</a><br>

<div class="im HOEnZb">Sent from the ITK - Users mailing list archive at Nabble.com.<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
</div></div></blockquote></div><br></div>