|
|
(2 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| ==MutualInformationImageToImageFilter.cxx== | | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions. |
| <source lang="cpp">
| | }} |
| #include "itkMutualInformationImageToImageMetric.h"
| |
| #include "itkRandomImageSource.h"
| |
| #include "itkTranslationTransform.h"
| |
| | |
| //typedef itk::Image< unsigned char, 2> ImageType;
| |
| typedef itk::Image< float, 2> ImageType;
| |
| | |
| int main( int argc, char *argv[] )
| |
| {
| |
| itk::Size<2> size;
| |
| size.Fill(10);
| |
| | |
| itk::RandomImageSource<ImageType>::Pointer randomImageSource1 = itk::RandomImageSource<ImageType>::New();
| |
| randomImageSource1->SetNumberOfThreads(1); // to produce non-random results
| |
| randomImageSource1->SetSize(size);
| |
| randomImageSource1->Update();
| |
|
| |
| ImageType::Pointer fixedImage = randomImageSource1->GetOutput();
| |
|
| |
| itk::RandomImageSource<ImageType>::Pointer randomImageSource2 = itk::RandomImageSource<ImageType>::New();
| |
| randomImageSource2->SetNumberOfThreads(1); // to produce non-random results
| |
| randomImageSource2->SetSize(size);
| |
| randomImageSource2->Update();
| |
| | |
| ImageType::Pointer movingImage = randomImageSource2->GetOutput();
| |
|
| |
| typedef itk::TranslationTransform<double, 2> TranslationTransformType; // This cannot be float for some reason?
| |
| TranslationTransformType::Pointer transform = TranslationTransformType::New();
| |
|
| |
| typedef itk::MutualInformationImageToImageMetric<ImageType, ImageType > MetricType;
| |
| | |
| MetricType::Pointer metric = MetricType::New();
| |
|
| |
| metric->SetTransform(transform);
| |
| | |
| metric->SetFixedImageStandardDeviation( 0.4 );
| |
| metric->SetMovingImageStandardDeviation( 0.4 );
| |
| | |
| metric->SetFixedImage(fixedImage);
| |
| metric->SetMovingImage(movingImage);
| |
|
| |
| //MetricType::ParametersType parameters;
| |
| TranslationTransformType::ParametersType parameters;
| |
| parameters.SetSize(2);
| |
| parameters.Fill(0); | |
| std::cout << "parameters: " << parameters << std::endl;
| |
|
| |
| MetricType::MeasureType value = metric->GetValue(parameters);
| |
|
| |
| std::cout << "Value: " << value << std::endl;
| |
|
| |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| | |
| </source>
| |
| | |
| {{ITKCMakeLists|MutualInformationImageToImageFilter}}
| |