[5d12a0]: / src / padImage.cxx

Download this file

67 lines (53 with data), 1.9 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
#include <nanobind/nanobind.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/ndarray.h>
#include <exception>
#include <vector>
#include <string>
#include "itkImage.h"
#include "itkConstantPadImageFilter.h"
#include "antsImage.h"
namespace nb = nanobind;
using namespace nb::literals;
template < typename ImageType >
AntsImage<ImageType> padImage( AntsImage<ImageType> & antsImage,
std::vector<int> lowerPadDims,
std::vector<int> upperPadDims,
float padValue )
{
typedef typename ImageType::Pointer ImagePointerType;
typename ImageType::Pointer itkImage = antsImage.ptr;
typename ImageType::SizeType lowerExtendRegion;
lowerExtendRegion[0] = lowerPadDims[0];
lowerExtendRegion[1] = lowerPadDims[1];
if (lowerPadDims.size() == 3)
{
lowerExtendRegion[2] = lowerPadDims[2];
}
typename ImageType::SizeType upperExtendRegion;
upperExtendRegion[0] = upperPadDims[0];
upperExtendRegion[1] = upperPadDims[1];
if (upperPadDims.size() == 3)
{
upperExtendRegion[2] = upperPadDims[2];
}
//ImageType::PixelType constantPixel = padValue;
typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadImageFilterType;
typename PadImageFilterType::Pointer padFilter = PadImageFilterType::New();
padFilter->SetInput( itkImage );
padFilter->SetPadLowerBound( lowerExtendRegion );
padFilter->SetPadUpperBound( upperExtendRegion );
padFilter->SetConstant( padValue );
padFilter->Update();
FixNonZeroIndex<ImageType>( padFilter->GetOutput() );
AntsImage<ImageType> myImage = { padFilter->GetOutput() };
return myImage;
}
void local_padImage(nb::module_ &m)
{
m.def("padImage", &padImage<itk::Image<float, 2>>);
m.def("padImage", &padImage<itk::Image<float, 3>>);
m.def("padImage", &padImage<itk::Image<float, 4>>);
}