[5d12a0]: / src / antsImageUtils.cxx

Download this file

147 lines (113 with data), 5.8 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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#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 <algorithm>
#include <vector>
#include <string>
#include "itkAddImageFilter.h"
#include "itkDefaultConvertPixelTraits.h"
#include "itkMultiplyImageFilter.h"
#include "itkImage.h"
#include "itkVectorImage.h"
#include "itkImageBase.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkNeighborhoodIterator.h"
#include "itkPermuteAxesImageFilter.h"
#include "itkCentralDifferenceImageFunction.h"
#include "itkContinuousIndex.h"
#include "vnl/vnl_matrix.h"
#include "vnl/vnl_vector.h"
#include "vnl/algo/vnl_determinant.h"
#include "antsImage.h"
namespace nb = nanobind;
using namespace nb::literals;
template < typename ImageType >
std::vector<std::vector<float> > TransformIndexToPhysicalPoint( AntsImage<ImageType> & antsImage,
std::vector<std::vector<int> > indices )
{
typedef typename ImageType::Pointer ImagePointerType ;
typedef typename ImageType::PointType PointType;
typedef typename PointType::CoordRepType CoordRepType;
typedef typename itk::ContinuousIndex<CoordRepType, ImageType::ImageDimension> IndexType;
const unsigned int nDim = ImageType::ImageDimension;
ImagePointerType image = antsImage.ptr;
unsigned long N = indices.size(); // number of indices to convert
//Rcpp::NumericMatrix points( N, nDim ) ;
std::vector<std::vector<float> > points(N, std::vector<float>(nDim));
IndexType itkindex;
PointType itkpoint;
for( unsigned int j = 0; j < N; j++)
{
for( unsigned int i = 0; i < nDim; i++ )
{
itkindex[i] = static_cast<CoordRepType>( indices[j][i] - 1.0 );
}
image->TransformContinuousIndexToPhysicalPoint( itkindex, itkpoint );
for ( int i = 0; i < nDim; i++ )
{
points[j][i] = itkpoint[i];
}
}
return points;
}
template < typename ImageType >
std::vector<std::vector<float> > TransformPhysicalPointToIndex( AntsImage<ImageType> & antsImage,
std::vector<std::vector<float> > points )
{
typedef typename ImageType::Pointer ImagePointerType ;
typedef typename ImageType::PointType PointType;
typedef typename PointType::CoordRepType CoordRepType;
typedef typename itk::ContinuousIndex<CoordRepType, ImageType::ImageDimension> IndexType;
const unsigned int nDim = ImageType::ImageDimension;
ImagePointerType image = antsImage.ptr;
unsigned long N = points.size();
std::vector<std::vector<float> > indices( N, std::vector<float>(nDim) );
IndexType itkindex;
PointType itkpoint;
for( unsigned int j = 0; j < N; j++)
{
for( unsigned int i = 0; i < nDim; i++ )
{
itkpoint[i] = static_cast<CoordRepType>( points[j][i] );
}
image->TransformPhysicalPointToContinuousIndex( itkpoint, itkindex );
for ( int i = 0; i < nDim; i++ )
{
indices[j][i] = itkindex[i] + 1.0;
}
}
return indices;
}
void local_antsImageUtils(nb::module_ &m)
{
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned char, 2>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned char, 3>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned char, 4>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned int, 2>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned int, 3>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<unsigned int, 4>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<float, 2>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<float, 3>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<float, 4>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<double, 2>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<double, 3>>);
m.def("TransformIndexToPhysicalPoint", &TransformIndexToPhysicalPoint<itk::Image<double, 4>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned char, 2>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned char, 3>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned char, 4>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned int, 2>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned int, 3>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<unsigned int, 4>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<float, 2>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<float, 3>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<float, 4>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<double, 2>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<double, 3>>);
m.def("TransformPhysicalPointToIndex", &TransformPhysicalPointToIndex<itk::Image<double, 4>>);
}