NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
addBoundary1d.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/Core/Types.hpp"
39 #include "NumCpp/NdArray.hpp"
40 
41 #include <string>
42 
43 namespace nc
44 {
45  namespace filter
46  {
47  namespace boundary
48  {
49  //============================================================================
50  // Method Description:
59  template<typename dtype>
60  NdArray<dtype> addBoundary1d(const NdArray<dtype>& inImage, Boundary inBoundaryType, uint32 inKernalSize, dtype inConstantValue = 0)
61  {
63 
64  if (inKernalSize % 2 == 0)
65  {
66  THROW_INVALID_ARGUMENT_ERROR("input kernal size must be an odd value.");
67  }
68 
69  const uint32 boundarySize = inKernalSize / 2; // integer division
70 
71  switch (inBoundaryType)
72  {
73  case Boundary::REFLECT:
74  {
75  return reflect1d(inImage, boundarySize);
76  }
77  case Boundary::CONSTANT:
78  {
79  return constant1d(inImage, boundarySize, inConstantValue);
80  }
81  case Boundary::NEAREST:
82  {
83  return nearest1d(inImage, boundarySize);
84  }
85  case Boundary::MIRROR:
86  {
87  return mirror1d(inImage, boundarySize);
88  }
89  case Boundary::WRAP:
90  {
91  return wrap1d(inImage, boundarySize);
92  }
93  default:
94  {
95  // This can't actually happen but just adding to get rid of compiler warning
97  }
98  }
99 
100  return NdArray<dtype>(); // get rid of compiler warning
101  }
102  } // namespace boundary
103  } // namespace filter
104 } // 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 > constant1d(const NdArray< dtype > &inImage, uint32 inBoundarySize, dtype inConstantValue)
Definition: constant1d.hpp:51
NdArray< dtype > addBoundary1d(const NdArray< dtype > &inImage, Boundary inBoundaryType, uint32 inKernalSize, dtype inConstantValue=0)
Definition: addBoundary1d.hpp:60
NdArray< dtype > wrap1d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: wrap1d.hpp:50
NdArray< dtype > mirror1d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: mirror1d.hpp:51
NdArray< dtype > reflect1d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: reflect1d.hpp:52
NdArray< dtype > nearest1d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: nearest1d.hpp:49
Boundary
Boundary condition to apply to the image filter.
Definition: Boundary.hpp:37
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40