Diff of /src/padImage.cxx [000000] .. [5d12a0]

Switch to unified view

a b/src/padImage.cxx
1
2
#include <nanobind/nanobind.h>
3
#include <nanobind/stl/vector.h>
4
#include <nanobind/stl/string.h>
5
#include <nanobind/stl/tuple.h>
6
#include <nanobind/ndarray.h>
7
8
#include <exception>
9
#include <vector>
10
#include <string>
11
12
#include "itkImage.h"
13
#include "itkConstantPadImageFilter.h"
14
15
#include "antsImage.h"
16
17
namespace nb = nanobind;
18
using namespace nb::literals;
19
20
template < typename ImageType >
21
AntsImage<ImageType> padImage( AntsImage<ImageType> & antsImage,
22
                      std::vector<int> lowerPadDims,
23
                      std::vector<int> upperPadDims,
24
                      float padValue )
25
{
26
  typedef typename ImageType::Pointer ImagePointerType;
27
  typename ImageType::Pointer itkImage = antsImage.ptr;
28
29
30
  typename ImageType::SizeType lowerExtendRegion;
31
  lowerExtendRegion[0] = lowerPadDims[0];
32
  lowerExtendRegion[1] = lowerPadDims[1];
33
  if (lowerPadDims.size() == 3)
34
  {
35
    lowerExtendRegion[2] = lowerPadDims[2];
36
  }
37
38
  typename ImageType::SizeType upperExtendRegion;
39
  upperExtendRegion[0] = upperPadDims[0];
40
  upperExtendRegion[1] = upperPadDims[1];
41
  if (upperPadDims.size() == 3)
42
  {
43
    upperExtendRegion[2] = upperPadDims[2];
44
  }
45
46
  //ImageType::PixelType constantPixel = padValue;
47
  typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadImageFilterType;
48
  typename PadImageFilterType::Pointer padFilter = PadImageFilterType::New();
49
  padFilter->SetInput( itkImage );
50
  padFilter->SetPadLowerBound( lowerExtendRegion );
51
  padFilter->SetPadUpperBound( upperExtendRegion );
52
  padFilter->SetConstant( padValue );
53
  padFilter->Update();
54
  FixNonZeroIndex<ImageType>( padFilter->GetOutput() );
55
56
  AntsImage<ImageType> myImage = { padFilter->GetOutput() };
57
  return myImage;
58
}
59
60
void local_padImage(nb::module_ &m) 
61
{
62
  m.def("padImage", &padImage<itk::Image<float, 2>>);
63
  m.def("padImage", &padImage<itk::Image<float, 3>>);
64
  m.def("padImage", &padImage<itk::Image<float, 4>>);
65
}
66