NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
constant2d.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Shape.hpp"
32 #include "NumCpp/Core/Slice.hpp"
33 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 namespace nc
38 {
39  namespace filter
40  {
41  namespace boundary
42  {
43  //============================================================================
44  // Method Description:
53  template<typename dtype>
54  NdArray<dtype> constant2d(const NdArray<dtype>& inImage, uint32 inBoundarySize, dtype inConstantValue)
55  {
57 
58  const Shape inShape = inImage.shape();
59  Shape outShape(inShape);
60  outShape.rows += inBoundarySize * 2;
61  outShape.cols += inBoundarySize * 2;
62 
63  NdArray<dtype> outArray(outShape);
64  outArray.put(Slice(inBoundarySize, inBoundarySize + inShape.rows),
65  Slice(inBoundarySize, inBoundarySize + inShape.cols), inImage);
66  fillCorners(outArray, inBoundarySize, inConstantValue);
67 
68  outArray.put(Slice(0, inBoundarySize), Slice(inBoundarySize, inBoundarySize + inShape.cols), inConstantValue);
69  outArray.put(Slice(outShape.rows - inBoundarySize, outShape.rows),
70  Slice(inBoundarySize, inBoundarySize + inShape.cols), inConstantValue);
71  outArray.put(Slice(inBoundarySize, inBoundarySize + inShape.rows),
72  Slice(0, inBoundarySize), inConstantValue);
73  outArray.put(Slice(inBoundarySize, inBoundarySize + inShape.rows),
74  Slice(outShape.cols - inBoundarySize, outShape.cols), inConstantValue);
75 
76  return outArray;
77  }
78  } // namespace boundary
79  } // namespace filter
80 } // namespace nc
StaticAsserts.hpp
nc::filter::boundary::fillCorners
void fillCorners(NdArray< dtype > &inArray, uint32 inBorderWidth)
Definition: fillCorners.hpp:50
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
nc::NdArray< dtype >
nc::filter::boundary::constant2d
NdArray< dtype > constant2d(const NdArray< dtype > &inImage, uint32 inBoundarySize, dtype inConstantValue)
Definition: constant2d.hpp:54
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:40
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::put
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3729
fillCorners.hpp
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:45
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:44
Types.hpp
nc::Slice
A Class for slicing into NdArrays.
Definition: Slice.hpp:43
Slice.hpp