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