NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
generateCentroids.hpp
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <string>
32 #include <vector>
33 
36 #include "NumCpp/Core/Types.hpp"
42 #include "NumCpp/NdArray.hpp"
43 
44 namespace nc
45 {
46  namespace imageProcessing
47  {
48  //============================================================================
49  // Method Description:
59  template<typename dtype>
60  std::vector<Centroid<dtype>> generateCentroids(const NdArray<dtype>& inImageArray,
61  double inRate,
62  const std::string& inWindowType,
63  uint8 inBorderWidth = 0)
64  {
66 
67  uint8 borderWidthPre = 0;
68  uint8 borderWidthPost = 0;
69  if (inWindowType == "pre")
70  {
71  borderWidthPre = inBorderWidth;
72  }
73  else if (inWindowType == "post")
74  {
75  borderWidthPost = inBorderWidth;
76  }
77  else
78  {
79  THROW_INVALID_ARGUMENT_ERROR("input window type options are ['pre', 'post']");
80  }
81 
82  // generate the threshold
83  dtype threshold = generateThreshold(inImageArray, inRate);
84 
85  // apply the threshold to get xcds
86  NdArray<bool> xcds = applyThreshold(inImageArray, threshold);
87 
88  // window around the xcds
89  if (borderWidthPre > 0)
90  {
91  xcds = windowExceedances(xcds, borderWidthPre);
92  }
93 
94  // cluster the exceedances
95  std::vector<Cluster<dtype>> clusters = clusterPixels(inImageArray, xcds, borderWidthPost);
96 
97  // centroid the clusters
98  return centroidClusters(clusters);
99  }
100  } // namespace imageProcessing
101 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:56
std::vector< Centroid< dtype > > centroidClusters(const std::vector< Cluster< dtype >> &inClusters)
Definition: centroidClusters.hpp:50
std::vector< Centroid< dtype > > generateCentroids(const NdArray< dtype > &inImageArray, double inRate, const std::string &inWindowType, uint8 inBorderWidth=0)
Definition: generateCentroids.hpp:60
NdArray< bool > windowExceedances(const NdArray< bool > &inExceedances, uint8 inBorderWidth) noexcept
Definition: windowExceedances.hpp:49
std::vector< Cluster< dtype > > clusterPixels(const NdArray< dtype > &inImageArray, const NdArray< bool > &inExceedances, uint8 inBorderWidth=0)
Definition: clusterPixels.hpp:53
NdArray< bool > applyThreshold(const NdArray< dtype > &inImageArray, dtype inThreshold)
Definition: applyThreshold.hpp:46
Definition: Coordinate.hpp:45
std::uint8_t uint8
Definition: Types.hpp:42