NumCpp  2.1.0
A C++ implementation of the Python Numpy library
nearest2d.hpp
Go to the documentation of this file.
1 #pragma once
30 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Slice.hpp"
34 #include "NumCpp/Core/Types.hpp"
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  namespace filter
41  {
42  namespace boundary
43  {
44  //============================================================================
45  // Method Description:
53  template<typename dtype>
54  NdArray<dtype> nearest2d(const NdArray<dtype>& inImage, uint32 inBoundarySize)
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);
67 
68  for (uint32 row = 0; row < inBoundarySize; ++row)
69  {
70  // bottom
71  outArray.put(row,
72  Slice(inBoundarySize, inBoundarySize + inShape.cols),
73  inImage(0, Slice(0, inShape.cols)));
74 
75  // top
76  outArray.put(row + inBoundarySize + inShape.rows,
77  Slice(inBoundarySize, inBoundarySize + inShape.cols),
78  inImage(inShape.rows - 1, Slice(0, inShape.cols)));
79  }
80 
81  for (uint32 col = 0; col < inBoundarySize; ++col)
82  {
83  // left
84  outArray.put(Slice(inBoundarySize, inBoundarySize + inShape.rows),
85  col,
86  inImage(Slice(0, inShape.rows), 0));
87 
88  // right
89  outArray.put(Slice(inBoundarySize, inBoundarySize + inShape.rows),
90  col + inBoundarySize + inShape.cols,
91  inImage(Slice(0, inShape.rows), inShape.cols - 1));
92  }
93 
94  return outArray;
95  }
96  } // namespace boundary
97  } // namespace filter
98 } // namespace nc
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:4312
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< dtype >
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:3685
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
nc::filter::boundary::nearest2d
NdArray< dtype > nearest2d(const NdArray< dtype > &inImage, uint32 inBoundarySize)
Definition: nearest2d.hpp:54
Types.hpp
nc::Slice
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
Slice.hpp