NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
addBoundary2d.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <string>
31 
34 #include "NumCpp/Core/Types.hpp"
41 #include "NumCpp/NdArray.hpp"
42 
43 namespace nc
44 {
45  namespace filter
46  {
47  namespace boundary
48  {
49  //============================================================================
50  // Method Description:
59  template<typename dtype>
61  Boundary inBoundaryType,
62  uint32 inKernalSize,
63  dtype inConstantValue = 0)
64  {
66 
67  if (inKernalSize % 2 == 0)
68  {
69  THROW_INVALID_ARGUMENT_ERROR("input kernal size must be an odd value.");
70  }
71 
72  const uint32 boundarySize = inKernalSize / 2; // integer division
73 
74  switch (inBoundaryType)
75  {
76  case Boundary::REFLECT:
77  {
78  return reflect2d(inImage, boundarySize);
79  }
80  case Boundary::CONSTANT:
81  {
82  return constant2d(inImage, boundarySize, inConstantValue);
83  }
84  case Boundary::NEAREST:
85  {
86  return nearest2d(inImage, boundarySize);
87  }
88  case Boundary::MIRROR:
89  {
90  return mirror2d(inImage, boundarySize);
91  }
92  case Boundary::WRAP:
93  {
94  return wrap2d(inImage, boundarySize);
95  }
96  default:
97  {
98  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
99  return {}; // get rid of compiler warning
100  }
101  }
102  }
103  } // namespace boundary
104  } // namespace filter
105 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
NdArray< dtype > constant2d(const NdArray< dtype > &inImage, uint32 inBoundarySize, dtype inConstantValue)
Definition: constant2d.hpp:53
NdArray< dtype > mirror2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: mirror2d.hpp:52
NdArray< dtype > addBoundary2d(const NdArray< dtype > &inImage, Boundary inBoundaryType, uint32 inKernalSize, dtype inConstantValue=0)
Definition: addBoundary2d.hpp:60
NdArray< dtype > nearest2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: nearest2d.hpp:52
NdArray< dtype > reflect2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: reflect2d.hpp:53
NdArray< dtype > wrap2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: wrap2d.hpp:52
Boundary
Boundary condition to apply to the image filter.
Definition: Boundary.hpp:38
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40