<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi all,</div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">Is it possible to use the itkMutualInformationImageToImageMetric class by it self, to calculate mutual information values between two data sets?</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">I currently implemented something like below, but get positive as well as negative values.</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new
 york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">Should I set up a full registration pipeline instead (like Examples/Registration/ImageRegistration2.cxx) and get the MI value after one iteration (optimizer-&gt;SetNumberOfIterations(1))?</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">Thanks Maarten</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0);
 font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br>#include &lt;vector&gt;<br>#include &lt;fstream&gt;<br><br>#include "itkImage.h"<br>#include "itkMutualInformationImageToImageMetric.h"<br>#include "itkTranslationTransform.h"<br>#include "itkLinearInterpolateImageFunction.h"<br><br>const unsigned int Dimension = 1;<br>typedef double PixelType;<br>typedef itk::Image&lt;PixelType, Dimension&gt; ImageType;<br><br>ImageType::Pointer readData(const std::string&amp; filename);<br><br>int main(int argc, const char* argv[])<br>{<br>&nbsp; typedef itk::MutualInformationImageToImageMetric&lt;ImageType, ImageType&gt;&nbsp;&nbsp;&nbsp; MetricType;<br>&nbsp; typedef itk::TranslationTransform&lt;double, Dimension&gt;&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TransformType;<br>&nbsp; typedef itk::LinearInterpolateImageFunction&lt;ImageType, double&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; InterpolatorType;<br><br>&nbsp; TransformType::Pointer transform = TransformType::New();<br>&nbsp; transform-&gt;SetIdentity();<br>&nbsp; InterpolatorType::Pointer interpolator = InterpolatorType::New();<br><br>&nbsp;&nbsp;&nbsp; std::string file1 = "C:\\Users\\Maarten\\Documents\\Visual Studio 2010\\Projects\\itkMI\\files\\X2.txt";<br>&nbsp;&nbsp;&nbsp; std::string file2 = "C:\\Users\\Maarten\\Documents\\Visual Studio 2010\\Projects\\itkMI\\files\\Y2.txt";<br>&nbsp;&nbsp;&nbsp; ImageType::Pointer data1 = readData(file1);<br>&nbsp;&nbsp;&nbsp; ImageType::Pointer data2 = readData(file2);<br><br>&nbsp;&nbsp;&nbsp; interpolator-&gt;SetInputImage(data2);<br><br>&nbsp;&nbsp;&nbsp; MetricType::Pointer metric =
 MetricType::New();<br>&nbsp;&nbsp;&nbsp; metric-&gt;SetFixedImage(data1);<br>&nbsp;&nbsp;&nbsp; metric-&gt;SetFixedImageRegion(data1-&gt;GetLargestPossibleRegion());<br>&nbsp;&nbsp;&nbsp; metric-&gt;SetMovingImage(data2);<br>&nbsp;&nbsp;&nbsp; metric-&gt;SetTransform(transform);<br>&nbsp;&nbsp;&nbsp; metric-&gt;SetInterpolator(interpolator);<br>&nbsp;&nbsp;&nbsp; //metric-&gt;ReinitializeSeed(12345); // with constant seed value -&gt; deterministic<br>&nbsp; //metric-&gt;SetFixedImageStandardDeviation(&nbsp; 0.4 );<br>&nbsp; //metric-&gt;SetMovingImageStandardDeviation( 0.4 );<br>&nbsp;&nbsp;&nbsp; const unsigned int numberOfPixels = data1-&gt;GetBufferedRegion().GetNumberOfPixels();<br>&nbsp;&nbsp;&nbsp; //metric-&gt;SetNumberOfSpatialSamples( numberOfPixels*0.1 );<br><br>&nbsp;&nbsp;&nbsp; MetricType::MeasureType measure = metric-&gt;GetValue(transform-&gt;GetParameters());<br><br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "MI value: " &lt;&lt; measure
 &lt;&lt; std::endl;<br><br>&nbsp;&nbsp;&nbsp; return 1;<br>}<br><br>ImageType::Pointer readData(const std::string&amp; filename)<br>{<br>&nbsp;&nbsp;&nbsp; ImageType::Pointer data = ImageType::New();<br>&nbsp;&nbsp;&nbsp; data-&gt;Initialize();<br><br>&nbsp;&nbsp;&nbsp; typedef itk::ImageRegionIteratorWithIndex&lt;ImageType&gt; IteratorType;<br><br>&nbsp;&nbsp;&nbsp; std::vector&lt;double&gt; values;<br>&nbsp;&nbsp;&nbsp; std::ifstream file(filename);<br>&nbsp;&nbsp;&nbsp; if( file.is_open() )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double value;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while( !file.eof() )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; file &gt;&gt; value;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; values.push_back(value);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; unsigned int numValues =
 values.size();<br>&nbsp;&nbsp;&nbsp; if( 0 &lt; numValues )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // maybe use itk::ImportImageFilter?<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ImageType::IndexType start;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; start[0] = 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ImageType::SizeType size;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size[0] = numValues;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ImageType::RegionType region;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; region.SetSize(size);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; region.SetIndex(start);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; data-&gt;SetRegions(region);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; data-&gt;Allocate();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ImageType::PointType origin;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; origin[0] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 data-&gt;SetOrigin(origin);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ImageType::SpacingType spacing;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; spacing[0] = 1.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; data-&gt;SetSpacing(spacing);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IteratorType it(data, data-&gt;GetLargestPossibleRegion());<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i = 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ( it.GoToBegin(); !it.IsAtEnd(); ++it, ++i)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; it.Set(values[i]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return data;<br>}<br></div></div></body></html>