NumCpp  2.4.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:
60  template<typename dtype>
61  std::vector<Centroid<dtype> > generateCentroids(const NdArray<dtype>& inImageArray, double inRate, const std::string& inWindowType, uint8 inBorderWidth = 0)
62  {
64 
65  uint8 borderWidthPre = 0;
66  uint8 borderWidthPost = 0;
67  if (inWindowType == "pre")
68  {
69  borderWidthPre = inBorderWidth;
70  }
71  else if (inWindowType == "post")
72  {
73  borderWidthPost = inBorderWidth;
74  }
75  else
76  {
77  THROW_INVALID_ARGUMENT_ERROR("input window type options are ['pre', 'post']");
78  }
79 
80  // generate the threshold
81  dtype threshold = generateThreshold(inImageArray, inRate);
82 
83  // apply the threshold to get xcds
84  NdArray<bool> xcds = applyThreshold(inImageArray, threshold);
85 
86  // window around the xcds
87  if (borderWidthPre > 0)
88  {
89  xcds = windowExceedances(xcds, borderWidthPre);
90  }
91 
92  // cluster the exceedances
93  std::vector<Cluster<dtype> > clusters = clusterPixels(inImageArray, xcds, borderWidthPost);
94 
95  // centroid the clusters
96  return centroidClusters(clusters);
97  }
98  } // namespace imageProcessing
99 } // namespace nc
StaticAsserts.hpp
centroidClusters.hpp
nc::imageProcessing::clusterPixels
std::vector< Cluster< dtype > > clusterPixels(const NdArray< dtype > &inImageArray, const NdArray< bool > &inExceedances, uint8 inBorderWidth=0)
Definition: clusterPixels.hpp:54
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
windowExceedances.hpp
nc::imageProcessing::generateThreshold
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:57
nc::uint8
std::uint8_t uint8
Definition: Types.hpp:42
clusterPixels.hpp
nc::NdArray< dtype >
NdArray.hpp
generateThreshold.hpp
nc::imageProcessing::windowExceedances
NdArray< bool > windowExceedances(const NdArray< bool > &inExceedances, uint8 inBorderWidth) noexcept
Definition: windowExceedances.hpp:50
nc::imageProcessing::centroidClusters
std::vector< Centroid< dtype > > centroidClusters(const std::vector< Cluster< dtype > > &inClusters)
Definition: centroidClusters.hpp:51
nc
Definition: Coordinate.hpp:44
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::imageProcessing::applyThreshold
NdArray< bool > applyThreshold(const NdArray< dtype > &inImageArray, dtype inThreshold)
Definition: applyThreshold.hpp:47
nc::imageProcessing::generateCentroids
std::vector< Centroid< dtype > > generateCentroids(const NdArray< dtype > &inImageArray, double inRate, const std::string &inWindowType, uint8 inBorderWidth=0)
Definition: generateCentroids.hpp:61
applyThreshold.hpp
Types.hpp