NumCpp  1.0
A C++ implementation of the Python Numpy library
windowExceedances.hpp
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <cmath>
37 
38 namespace nc
39 {
40  namespace imageProcessing
41  {
42  //============================================================================
43  // Method Description:
51  inline NdArray<bool> windowExceedances(const NdArray<bool>& inExceedances, uint8 inBorderWidth) noexcept
52  {
53  // not the most efficient way to do things, but the easist...
54  NdArray<bool> xcds(inExceedances);
55  const Shape inShape = xcds.shape();
56  for (uint8 border = 0; border < inBorderWidth; ++border)
57  {
58  for (int32 row = 0; row < static_cast<int32>(inShape.rows); ++row)
59  {
60  for (int32 col = 0; col < static_cast<int32>(inShape.cols); ++col)
61  {
62  if (inExceedances(row, col))
63  {
64  xcds(std::max(row - 1, 0), std::max(col - 1, 0)) = true;
65  xcds(std::max(row - 1, 0), col) = true;
66  xcds(std::max(row - 1, 0), std::min<int32>(col + 1, inShape.cols - 1)) = true;
67 
68  xcds(row, std::max<int32>(col - 1, 0)) = true;
69  xcds(row, std::min<int32>(col + 1, inShape.cols - 1)) = true;
70 
71  xcds(std::min<int32>(row + 1, inShape.rows - 1), std::max(col - 1, 0)) = true;
72  xcds(std::min<int32>(row + 1, inShape.rows - 1), col) = true;
73  xcds(std::min<int32>(row + 1, inShape.rows - 1), std::min<int32>(col + 1, inShape.cols - 1)) = true;
74  }
75  }
76  }
77  }
78 
79  return xcds;
80  }
81  }
82 }
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
nc::int32
std::int32_t int32
Definition: Types.hpp:37
nc::uint8
std::uint8_t uint8
Definition: Types.hpp:43
nc::NdArray< bool >
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::imageProcessing::windowExceedances
NdArray< bool > windowExceedances(const NdArray< bool > &inExceedances, uint8 inBorderWidth) noexcept
Definition: windowExceedances.hpp:51
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::max
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:46
Types.hpp