NumCpp  2.10.1
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::filter::boundary
44 {
45  //============================================================================
46  // Method Description:
55  template<typename dtype>
57  Boundary inBoundaryType,
58  uint32 inKernalSize,
59  dtype inConstantValue = 0)
60  {
62 
63  if (inKernalSize % 2 == 0)
64  {
65  THROW_INVALID_ARGUMENT_ERROR("input kernal size must be an odd value.");
66  }
67 
68  const uint32 boundarySize = inKernalSize / 2; // integer division
69 
70  switch (inBoundaryType)
71  {
72  case Boundary::REFLECT:
73  {
74  return reflect2d(inImage, boundarySize);
75  }
76  case Boundary::CONSTANT:
77  {
78  return constant2d(inImage, boundarySize, inConstantValue);
79  }
80  case Boundary::NEAREST:
81  {
82  return nearest2d(inImage, boundarySize);
83  }
84  case Boundary::MIRROR:
85  {
86  return mirror2d(inImage, boundarySize);
87  }
88  case Boundary::WRAP:
89  {
90  return wrap2d(inImage, boundarySize);
91  }
92  default:
93  {
94  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
95  return {}; // get rid of compiler warning
96  }
97  }
98  }
99 } // namespace nc::filter::boundary
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
Definition: addBoundary1d.hpp:44
NdArray< dtype > constant2d(const NdArray< dtype > &inImage, uint32 inBoundarySize, dtype inConstantValue)
Definition: constant2d.hpp:49
NdArray< dtype > mirror2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: mirror2d.hpp:48
NdArray< dtype > addBoundary2d(const NdArray< dtype > &inImage, Boundary inBoundaryType, uint32 inKernalSize, dtype inConstantValue=0)
Definition: addBoundary2d.hpp:56
NdArray< dtype > nearest2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: nearest2d.hpp:48
NdArray< dtype > reflect2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: reflect2d.hpp:49
NdArray< dtype > wrap2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: wrap2d.hpp:48
Boundary
Boundary condition to apply to the image filter.
Definition: Boundary.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40