NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
windowExceedances.hpp
Go to the documentation of this file.
1 
28 
29 #pragma once
30 
31 #include "NumCpp/Core/Shape.hpp"
32 #include "NumCpp/Core/Types.hpp"
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <cmath>
36 
37 namespace nc
38 {
39  namespace imageProcessing
40  {
41  //============================================================================
42  // Method Description:
50  inline NdArray<bool> windowExceedances(const NdArray<bool>& inExceedances, uint8 inBorderWidth) noexcept
51  {
52  // not the most efficient way to do things, but the easist...
53  NdArray<bool> xcds(inExceedances);
54  const Shape inShape = xcds.shape();
55  for (uint8 border = 0; border < inBorderWidth; ++border)
56  {
57  for (int32 row = 0; row < static_cast<int32>(inShape.rows); ++row)
58  {
59  for (int32 col = 0; col < static_cast<int32>(inShape.cols); ++col)
60  {
61  if (inExceedances(row, col))
62  {
63  xcds(std::max(row - 1, 0), std::max(col - 1, 0)) = true;
64  xcds(std::max(row - 1, 0), col) = true;
65  xcds(std::max(row - 1, 0), std::min<int32>(col + 1, inShape.cols - 1)) = true;
66 
67  xcds(row, std::max<int32>(col - 1, 0)) = true;
68  xcds(row, std::min<int32>(col + 1, inShape.cols - 1)) = true;
69 
70  xcds(std::min<int32>(row + 1, inShape.rows - 1), std::max(col - 1, 0)) = true;
71  xcds(std::min<int32>(row + 1, inShape.rows - 1), col) = true;
72  xcds(std::min<int32>(row + 1, inShape.rows - 1), std::min<int32>(col + 1, inShape.cols - 1)) = true;
73  }
74  }
75  }
76  }
77 
78  return xcds;
79  }
80  } // namespace imageProcessing
81 } // namespace nc
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
NdArray< bool > windowExceedances(const NdArray< bool > &inExceedances, uint8 inBorderWidth) noexcept
Definition: windowExceedances.hpp:50
Definition: Coordinate.hpp:45
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:45
std::int32_t int32
Definition: Types.hpp:36
std::uint8_t uint8
Definition: Types.hpp:42