NumCpp  2.7.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 
33 #include "NumCpp/Core/Types.hpp"
39 #include "NumCpp/NdArray.hpp"
40 
41 #include <string>
42 #include <vector>
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, double inRate, const std::string& inWindowType, uint8 inBorderWidth = 0)
61  {
63 
64  uint8 borderWidthPre = 0;
65  uint8 borderWidthPost = 0;
66  if (inWindowType == "pre")
67  {
68  borderWidthPre = inBorderWidth;
69  }
70  else if (inWindowType == "post")
71  {
72  borderWidthPost = inBorderWidth;
73  }
74  else
75  {
76  THROW_INVALID_ARGUMENT_ERROR("input window type options are ['pre', 'post']");
77  }
78 
79  // generate the threshold
80  dtype threshold = generateThreshold(inImageArray, inRate);
81 
82  // apply the threshold to get xcds
83  NdArray<bool> xcds = applyThreshold(inImageArray, threshold);
84 
85  // window around the xcds
86  if (borderWidthPre > 0)
87  {
88  xcds = windowExceedances(xcds, borderWidthPre);
89  }
90 
91  // cluster the exceedances
92  std::vector<Cluster<dtype> > clusters = clusterPixels(inImageArray, xcds, borderWidthPost);
93 
94  // centroid the clusters
95  return centroidClusters(clusters);
96  }
97  } // namespace imageProcessing
98 } // 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 > > 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
std::vector< Centroid< dtype > > centroidClusters(const std::vector< Cluster< dtype > > &inClusters)
Definition: centroidClusters.hpp:50
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