<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->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 <vector><br>#include <fstream><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<PixelType, Dimension> ImageType;<br><br>ImageType::Pointer readData(const std::string& filename);<br><br>int main(int argc, const char* argv[])<br>{<br> typedef itk::MutualInformationImageToImageMetric<ImageType, ImageType> MetricType;<br> typedef itk::TranslationTransform<double, Dimension>
TransformType;<br> typedef itk::LinearInterpolateImageFunction<ImageType, double> InterpolatorType;<br><br> TransformType::Pointer transform = TransformType::New();<br> transform->SetIdentity();<br> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br><br> std::string file1 = "C:\\Users\\Maarten\\Documents\\Visual Studio 2010\\Projects\\itkMI\\files\\X2.txt";<br> std::string file2 = "C:\\Users\\Maarten\\Documents\\Visual Studio 2010\\Projects\\itkMI\\files\\Y2.txt";<br> ImageType::Pointer data1 = readData(file1);<br> ImageType::Pointer data2 = readData(file2);<br><br> interpolator->SetInputImage(data2);<br><br> MetricType::Pointer metric =
MetricType::New();<br> metric->SetFixedImage(data1);<br> metric->SetFixedImageRegion(data1->GetLargestPossibleRegion());<br> metric->SetMovingImage(data2);<br> metric->SetTransform(transform);<br> metric->SetInterpolator(interpolator);<br> //metric->ReinitializeSeed(12345); // with constant seed value -> deterministic<br> //metric->SetFixedImageStandardDeviation( 0.4 );<br> //metric->SetMovingImageStandardDeviation( 0.4 );<br> const unsigned int numberOfPixels = data1->GetBufferedRegion().GetNumberOfPixels();<br> //metric->SetNumberOfSpatialSamples( numberOfPixels*0.1 );<br><br> MetricType::MeasureType measure = metric->GetValue(transform->GetParameters());<br><br> std::cout << "MI value: " << measure
<< std::endl;<br><br> return 1;<br>}<br><br>ImageType::Pointer readData(const std::string& filename)<br>{<br> ImageType::Pointer data = ImageType::New();<br> data->Initialize();<br><br> typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;<br><br> std::vector<double> values;<br> std::ifstream file(filename);<br> if( file.is_open() )<br> {<br> double value;<br> while( !file.eof() )<br> {<br> file >> value;<br> values.push_back(value);<br> }<br> }<br> unsigned int numValues =
values.size();<br> if( 0 < numValues )<br> {<br> // maybe use itk::ImportImageFilter?<br> ImageType::IndexType start;<br> start[0] = 0;<br> ImageType::SizeType size;<br> size[0] = numValues;<br> ImageType::RegionType region;<br> region.SetSize(size);<br> region.SetIndex(start);<br> data->SetRegions(region);<br> data->Allocate();<br><br> ImageType::PointType origin;<br> origin[0] = 0.0;<br>
data->SetOrigin(origin);<br> ImageType::SpacingType spacing;<br> spacing[0] = 1.0;<br> data->SetSpacing(spacing);<br><br> IteratorType it(data, data->GetLargestPossibleRegion());<br> int i = 0;<br> for ( it.GoToBegin(); !it.IsAtEnd(); ++it, ++i)<br> {<br> it.Set(values[i]);<br> }<br> }<br> return data;<br>}<br></div></div></body></html>