--- /dev/null
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+#ifndef __bbitkNormalizedCorrelationImageToImageMetric_h_INCLUDED__
+#define __bbitkNormalizedCorrelationImageToImageMetric_h_INCLUDED__
+
+#include "bbitk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+#include "bbitkImage.h"
+#include "itkFFTNormalizedCorrelationImageFilter.h"
+
+#include "itkRescaleIntensityImageFilter.h"
+#include "itkMinimumMaximumImageCalculator.h"
+
+
+#include <iostream>
+#include <string>
+
+
+namespace bbitk
+{
+
+class bbitk_EXPORT NormalizedCorrelationImageToImageMetric
+ :
+ public bbtk::AtomicBlackBox
+{
+ BBTK_BLACK_BOX_INTERFACE(NormalizedCorrelationImageToImageMetric,bbtk::AtomicBlackBox);
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+ BBTK_DECLARE_INPUT(In1,anyImagePointer);
+ BBTK_DECLARE_INPUT(In2,anyImagePointer);
+ BBTK_DECLARE_OUTPUT(Out,double);
+ BBTK_PROCESS(ProcessSwitch);
+ private :
+ inline void ProcessSwitch();
+ template <class T> void Process();
+
+ //=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(NormalizedCorrelationImageToImageMetric,bbtk::AtomicBlackBox);
+ BBTK_NAME("NormalizedCorrelationImageToImageMetric");
+ BBTK_AUTHOR("InfoDev");
+ BBTK_DESCRIPTION("No Description.");
+ BBTK_CATEGORY("empty");
+ BBTK_INPUT(NormalizedCorrelationImageToImageMetric,In1,"First input",anyImagePointer,"");
+ BBTK_INPUT(NormalizedCorrelationImageToImageMetric,In2,"Second input",anyImagePointer,"");
+ BBTK_OUTPUT(NormalizedCorrelationImageToImageMetric,Out,"First output",double,"");
+BBTK_END_DESCRIBE_BLACK_BOX(NormalizedCorrelationImageToImageMetric);
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+
+ //===================================================
+ void NormalizedCorrelationImageToImageMetric::ProcessSwitch()
+ {
+ bbtk::TypeInfo t = bbGetInputIn1().type();
+// BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->Process);
+ BBTK_TEMPLATE_ITK_IMAGE_DIM_3_SWITCH(t, this->Process , "Error format. (you need 3D short,float,double)") ;
+/*
+ BBTK_BEGIN_TEMPLATE_SWITCH(t)
+ BBTK_SWITCH_ITK_IMAGE_short_3(t,this->Process,)
+ BBTK_SWITCH_ITK_IMAGE_float_3(t,this->Process,)
+ BBTK_SWITCH_ITK_IMAGE_double_3(t,this->Process,)
+ BBTK_END_TEMPLATE_SWITCH(t)
+*/
+ }
+
+ //===================================================
+ template <class T>
+ void NormalizedCorrelationImageToImageMetric::Process()
+ {
+ printf("EED NormalizedCorrelationImageToImageMetric::Process Start \n");
+ using FloatImageType = itk::Image<float, 3>;
+ typedef T ImageType;
+ T* in1 = this->bbGetInputIn1().get<T*>();
+ T* in2 = this->bbGetInputIn2().get<T*>();
+
+ using CorrelationFilterType = itk::FFTNormalizedCorrelationImageFilter<ImageType, FloatImageType>;
+ auto correlationFilter = CorrelationFilterType::New();
+ correlationFilter->SetFixedImage( in1 );
+ correlationFilter->SetMovingImage( in2 );
+ correlationFilter->Update();
+
+
+ using RescaleFilterType = itk::RescaleIntensityImageFilter<FloatImageType, ImageType>;
+ auto rescaleFilter = RescaleFilterType::New();
+ rescaleFilter->SetInput(correlationFilter->GetOutput());
+ rescaleFilter->SetOutputMinimum(0);
+ rescaleFilter->SetOutputMaximum(255);
+ rescaleFilter->Update();
+ // itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png");
+
+ using MinimumMaximumImageCalculatorType = itk::MinimumMaximumImageCalculator<FloatImageType>;
+ MinimumMaximumImageCalculatorType::Pointer minimumMaximumImageCalculatorFilter = MinimumMaximumImageCalculatorType::New();
+ minimumMaximumImageCalculatorFilter->SetImage(correlationFilter->GetOutput());
+ minimumMaximumImageCalculatorFilter->Compute();
+
+ itk::Index<3> maximumCorrelationPatchCenter = minimumMaximumImageCalculatorFilter->GetIndexOfMaximum();
+ itk::Size<3> outputSize = correlationFilter->GetOutput()->GetLargestPossibleRegion().GetSize();
+ itk::Index<3> maximumCorrelationPatchCenterFixed;
+ maximumCorrelationPatchCenterFixed[0] = outputSize[0] / 2 - maximumCorrelationPatchCenter[0];
+ maximumCorrelationPatchCenterFixed[1] = outputSize[1] / 2 - maximumCorrelationPatchCenter[1];
+ maximumCorrelationPatchCenterFixed[2] = outputSize[2] / 2 - maximumCorrelationPatchCenter[2];
+
+ std::cout << "Maximum location: " << maximumCorrelationPatchCenter << std::endl;
+ std::cout << "Maximum location fixed: " << maximumCorrelationPatchCenterFixed << std::endl; // This is the value we expect!
+ std::cout << "Maximum value: " << minimumMaximumImageCalculatorFilter->GetMaximum() << std::endl; // If the images can be perfectly aligned, the value is 1
+
+ this->bbSetOutputOut( minimumMaximumImageCalculatorFilter->GetMaximum() );
+ printf("EED NormalizedCorrelationImageToImageMetric::Process End \n");
+
+ }
+
+ //-----------------------------------------------------------------
+ void NormalizedCorrelationImageToImageMetric::bbUserSetDefaultValues()
+ {
+ }
+
+ //-----------------------------------------------------------------
+ void NormalizedCorrelationImageToImageMetric::bbUserInitializeProcessing()
+ {
+ }
+
+ //-----------------------------------------------------------------
+ void NormalizedCorrelationImageToImageMetric::bbUserFinalizeProcessing()
+ {
+ }
+
+}// EO namespace bbitk
+#endif // __bbitkNormalizedCorrelationImageToImageMetric_h_INCLUDED__
+