49 template<
typename dtype>
56 using accumulator_t =
typename std::conditional<std::is_integral<dtype>::value,
int64,
double>::type;
74 centerOfMass(inCluster);
75 setEllipseProperties(inCluster);
84 [[nodiscard]]
double row() const noexcept
95 [[nodiscard]]
double col() const noexcept
117 [[nodiscard]]
double eod() const noexcept
128 [[nodiscard]]
double a() const noexcept
140 [[nodiscard]]
double b() const noexcept
153 return eccentricity_;
174 [[nodiscard]] std::string
str()
const
221 return !(*
this == rhs);
237 return intensity_ < rhs.intensity_ ? false :
true;
250 inStream << inCentriod.
str();
265 double eccentricity_{};
267 double orientation_{};
277 void centerOfMass(
const Cluster<dtype>& inCluster)
279 const Shape clusterShape(inCluster.height(), inCluster.width());
280 NdArray<dtype> clusterArray(clusterShape);
281 clusterArray.zeros();
283 const uint32 rowMin = inCluster.rowMin();
284 const uint32 colMin = inCluster.colMin();
286 for (
auto& pixel : inCluster)
288 clusterArray(pixel.row - rowMin, pixel.col - colMin) = pixel.intensity;
292 row_ = rowCol.front() + rowMin;
293 col_ = rowCol.back() + colMin;
302 void setEllipseProperties(
const Cluster<dtype>& inCluster)
noexcept
304 constexpr auto two =
static_cast<double>(2.);
306 auto m20 =
static_cast<double>(0.);
307 auto m02 =
static_cast<double>(0.);
308 auto m11 =
static_cast<double>(0.);
312 const auto& pixel = *iter;
313 const double deltaX = pixel.col - col_;
314 const double deltaY = pixel.row - row_;
316 m11 += deltaX * deltaY;
321 const auto numPixels =
static_cast<double>(inCluster.size());
326 double piece1 = m20 + m02;
332 const double lambda1 = piece1 - piece2;
333 const double lambda2 = piece1 + piece2;
335 eccentricity_ = std::sqrt(
static_cast<double>(1.) - lambda1 / lambda2);
336 orientation_ =
static_cast<double>(-0.5) * std::atan2(two * m11, m20 - m02);
337 a_ = two * std::sqrt(lambda2);
338 b_ = two * std::sqrt(lambda1);
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
bool operator<(const Centroid< dtype > &rhs) const noexcept
Definition Centroid.hpp:235
double eod() const noexcept
Definition Centroid.hpp:117
friend std::ostream & operator<<(std::ostream &inStream, const Centroid< dtype > &inCentriod)
Definition Centroid.hpp:248
double b() const noexcept
Definition Centroid.hpp:140
void print() const
Definition Centroid.hpp:189
accumulator_t intensity() const noexcept
Definition Centroid.hpp:106
double col() const noexcept
Definition Centroid.hpp:95
bool operator==(const Centroid< dtype > &rhs) const noexcept
Definition Centroid.hpp:202
Centroid(const Cluster< dtype > &inCluster)
Definition Centroid.hpp:70
double eccentricity() const noexcept
Definition Centroid.hpp:151
bool operator!=(const Centroid< dtype > &rhs) const noexcept
Definition Centroid.hpp:219
double row() const noexcept
Definition Centroid.hpp:84
std::string str() const
Definition Centroid.hpp:174
typename std::conditional< std::is_integral< dtype >::value, int64, double >::type accumulator_t
Definition Centroid.hpp:56
double a() const noexcept
Definition Centroid.hpp:128
double orientation() const noexcept
Definition Centroid.hpp:163
Holds the information for a cluster of pixels.
Definition Cluster.hpp:52
typename std::vector< Pixel< dtype > >::const_iterator const_iterator
Definition Cluster.hpp:58
Definition applyThreshold.hpp:34
std::string num2str(dtype inNumber)
Definition num2str.hpp:44
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition essentiallyEqual.hpp:47
constexpr dtype sqr(dtype inValue) noexcept
Definition sqr.hpp:42
NdArray< double > centerOfMass(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition centerOfMass.hpp:46
std::int64_t int64
Definition Types.hpp:35
std::uint32_t uint32
Definition Types.hpp:40