NumCpp  1.0
A C++ implementation of the Python Numpy library
generateCentroids.hpp
Go to the documentation of this file.
1 
30 #pragma once
31 
33 #include "NumCpp/Core/Types.hpp"
40 #include "NumCpp/NdArray.hpp"
41 
42 #include <string>
43 #include <vector>
44 
45 namespace nc
46 {
47  namespace imageProcessing
48  {
49  //============================================================================
50  // Method Description:
61  template<typename dtype>
62  std::vector<Centroid<dtype> > generateCentroids(const NdArray<dtype>& inImageArray, double inRate, const std::string inWindowType, uint8 inBorderWidth = 0)
63  {
65 
66  uint8 borderWidthPre = 0;
67  uint8 borderWidthPost = 0;
68  if (inWindowType.compare("pre") == 0)
69  {
70  borderWidthPre = inBorderWidth;
71  }
72  else if (inWindowType.compare("post") == 0)
73  {
74  borderWidthPost = inBorderWidth;
75  }
76  else
77  {
78  THROW_INVALID_ARGUMENT_ERROR("input window type options are ['pre', 'post']");
79  }
80 
81  // generate the threshold
82  dtype threshold = generateThreshold(inImageArray, inRate);
83 
84  // apply the threshold to get xcds
85  NdArray<bool> xcds = applyThreshold(inImageArray, threshold);
86 
87  // window around the xcds
88  if (borderWidthPre > 0)
89  {
90  xcds = windowExceedances(xcds, borderWidthPre);
91  }
92 
93  // cluster the exceedances
94  std::vector<Cluster<dtype> > clusters = clusterPixels(inImageArray, xcds, borderWidthPost);
95 
96  // centroid the clusters
97  return centroidClusters(clusters);
98  }
99  }
100 }
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:55
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
windowExceedances.hpp
nc::imageProcessing::generateThreshold
dtype generateThreshold(const NdArray< dtype > &inImageArray, double inRate)
Definition: generateThreshold.hpp:58
nc::uint8
std::uint8_t uint8
Definition: Types.hpp:43
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:51
nc::imageProcessing::centroidClusters
std::vector< Centroid< dtype > > centroidClusters(const std::vector< Cluster< dtype > > &inClusters)
Definition: centroidClusters.hpp:52
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::imageProcessing::applyThreshold
NdArray< bool > applyThreshold(const NdArray< dtype > &inImageArray, dtype inThreshold)
Definition: applyThreshold.hpp:48
applyThreshold.hpp
Types.hpp
nc::imageProcessing::generateCentroids
std::vector< Centroid< dtype > > generateCentroids(const NdArray< dtype > &inImageArray, double inRate, const std::string inWindowType, uint8 inBorderWidth=0)
Definition: generateCentroids.hpp:62