[5d12a0]: / src / antsImageMutualInformation.cxx

Download this file

53 lines (43 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <nanobind/nanobind.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/list.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/shared_ptr.h>
#include <exception>
#include <vector>
#include <string>
//#include <Rcpp.h>
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkMattesMutualInformationImageToImageMetricv4.h"
#include "antsImage.h"
namespace nb = nanobind;
using namespace nb::literals;
template <unsigned int Dimension>
double antsImageMutualInformation( AntsImage<itk::Image< float , Dimension >> & in_image1,
AntsImage<itk::Image< float , Dimension >> & in_image2 )
{
double mi = 1;
typedef itk::Image< float , Dimension > ImageType;
typedef typename ImageType::Pointer ImagePointerType;
ImagePointerType itkImage1 = in_image1.ptr;
ImagePointerType itkImage2 = in_image2.ptr;
typedef itk::MattesMutualInformationImageToImageMetricv4
<ImageType, ImageType, ImageType> MetricType;
unsigned int bins = 32;
typename MetricType::Pointer metric = MetricType::New();
metric->SetFixedImage( itkImage1 );
metric->SetMovingImage( itkImage2 );
metric->SetNumberOfHistogramBins( bins );
metric->Initialize();
mi = metric->GetValue();
return mi;
}
void local_antsImageMutualInformation(nb::module_ &m)
{
m.def("antsImageMutualInformation2D", &antsImageMutualInformation<2>);
m.def("antsImageMutualInformation3D", &antsImageMutualInformation<3>);
m.def("antsImageMutualInformation4D", &antsImageMutualInformation<4>);
}