33 #include <type_traits>
45 namespace imageProcessing
50 template<
typename dtype>
54 STATIC_ASSERT_ARITHMETIC(dtype);
57 using accumulator_t =
typename std::conditional<std::is_integral<dtype>::value,
int64,
double>::type;
75 centerOfMass(inCluster);
76 setEllipseProperties(inCluster);
85 double row() const noexcept
96 double col() const noexcept
118 double eod() const noexcept
129 double a() const noexcept
141 double b() const noexcept
154 return eccentricity_;
205 return (row_ == rhs.row_ && col_ == rhs.col_ && intensity_ == rhs.intensity_ &&
222 return !(*
this == rhs);
238 return intensity_ < rhs.intensity_ ? false :
true;
251 inStream << inCentriod.
str();
266 double eccentricity_;
278 void centerOfMass(
const Cluster<dtype>& inCluster)
280 const Shape clusterShape(inCluster.height(), inCluster.width());
281 NdArray<dtype> clusterArray(clusterShape);
282 clusterArray.zeros();
284 const uint32 rowMin = inCluster.rowMin();
285 const uint32 colMin = inCluster.colMin();
287 for (
auto& pixel : inCluster)
289 clusterArray(pixel.row - rowMin, pixel.col - colMin) = pixel.intensity;
293 row_ = rowCol.front() + rowMin;
294 col_ = rowCol.back() + colMin;
303 void setEllipseProperties(
const Cluster<dtype>& inCluster) noexcept
305 constexpr
double two =
static_cast<double>(2.);
307 double m20 =
static_cast<double>(0.);
308 double m02 =
static_cast<double>(0.);
309 double m11 =
static_cast<double>(0.);
313 const auto& pixel = *iter;
314 const double deltaX = pixel.col - col_;
315 const double deltaY = pixel.row - row_;
317 m11 += deltaX * deltaY;
322 const double numPixels =
static_cast<double>(inCluster.size());
327 double piece1 = m20 + m02;
333 const double lambda1 = piece1 - piece2;
334 const double lambda2 = piece1 + piece2;
336 eccentricity_ =
std::sqrt(
static_cast<double>(1.) - lambda1 / lambda2);
337 orientation_ =
static_cast<double>(-0.5) * std::atan2(two * m11, m20 - m02);
holds the information for a centroid
Definition: Centroid.hpp:52
bool operator<(const Centroid< dtype > &rhs) const noexcept
Definition: Centroid.hpp:236
double eod() const noexcept
Definition: Centroid.hpp:118
double b() const noexcept
Definition: Centroid.hpp:141
void print() const
Definition: Centroid.hpp:190
accumulator_t intensity() const noexcept
Definition: Centroid.hpp:107
double col() const noexcept
Definition: Centroid.hpp:96
bool operator==(const Centroid< dtype > &rhs) const noexcept
Definition: Centroid.hpp:203
Centroid(const Cluster< dtype > &inCluster)
Definition: Centroid.hpp:71
friend std::ostream & operator<<(std::ostream &inStream, const Centroid< dtype > &inCentriod)
Definition: Centroid.hpp:249
double eccentricity() const noexcept
Definition: Centroid.hpp:152
bool operator!=(const Centroid< dtype > &rhs) const noexcept
Definition: Centroid.hpp:220
double row() const noexcept
Definition: Centroid.hpp:85
std::string str() const
Definition: Centroid.hpp:175
typename std::conditional< std::is_integral< dtype >::value, int64, double >::type accumulator_t
Definition: Centroid.hpp:57
double a() const noexcept
Definition: Centroid.hpp:129
double orientation() const noexcept
Definition: Centroid.hpp:164
Holds the information for a cluster of pixels.
Definition: Cluster.hpp:55
typename std::vector< Pixel< dtype > >::const_iterator const_iterator
Definition: Cluster.hpp:61
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
constexpr dtype sqr(dtype inValue) noexcept
Definition: sqr.hpp:44
Definition: Coordinate.hpp:45
std::int64_t int64
Definition: Types.hpp:35
NdArray< double > centerOfMass(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: centerOfMass.hpp:47
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:48
std::uint32_t uint32
Definition: Types.hpp:40