13#include <QtConcurrent>
15#include "fits_debug.h"
16#include "fitsthresholddetector.h"
28 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
29 switch (stats.dataType)
31#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
33 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<int16_t>,
this, boundary);
36 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<uint16_t>,
this, boundary);
39 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<int32_t>,
this, boundary);
42 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<uint32_t>,
this, boundary);
45 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<float>,
this, boundary);
48 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<int64_t>,
this, boundary);
51 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<double>,
this, boundary);
55 return QtConcurrent::run(&FITSThresholdDetector::findOneStar<uint8_t>,
this, boundary);
58 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int16_t>, boundary);
61 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint16_t>, boundary);
64 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int32_t>, boundary);
67 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint32_t>, boundary);
70 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<float>, boundary);
73 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int64_t>, boundary);
76 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<double>, boundary);
80 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint8_t>, boundary);
88bool FITSThresholdDetector::findOneStar(
const QRect &boundary)
const
90 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
92 int subX = boundary.
x();
93 int subY = boundary.
y();
94 int subW = subX + boundary.
width();
95 int subH = subY + boundary.
height();
97 float massX = 0, massY = 0, totalMass = 0;
99 auto * buffer =
reinterpret_cast<T
const *
>(m_ImageData->getImageBuffer());
101 double THRESHOLD_PERCENTAGE = getValue(
"THRESHOLD_PERCENTAGE", 120.0).
toDouble();
103 double threshold = stats.mean[0] * THRESHOLD_PERCENTAGE / 100.0;
105 for (
int y = subY; y < subH; y++)
107 for (
int x = subX; x < subW; x++)
109 T pixel = buffer[x + y * stats.width];
110 if (pixel > threshold)
119 qCDebug(KSTARS_FITS) <<
"FITS: Weighted Center is X: " << massX / totalMass <<
" Y: " << massY / totalMass;
123 center->x = massX / totalMass + 0.5;
124 center->y = massY / totalMass + 0.5;
128 int maxR = qMin(subW - 1, subH - 1) / 2;
131 double critical_threshold = threshold * 0.7;
132 double running_threshold = threshold;
134 while (running_threshold >= critical_threshold)
136 for (
int r = maxR; r > 1; r--)
140 for (
float theta = 0; theta < 2 * M_PI; theta += (2 * M_PI) / 10.0)
142 int testX =
center->x + std::cos(theta) * r;
143 int testY =
center->y + std::sin(theta) * r;
146 if (testX < subX || testX > subW || testY < subY || testY > subH)
149 if (buffer[testX + testY * stats.width] > running_threshold)
166 running_threshold -= running_threshold * 0.1;
179 double FSum = 0, HF = 0, TF = 0, min = stats.min[0];
180 const double resolution = 1.0 / 20.0;
182 int cen_y = qRound(
center->y);
190 for (
double x = leftEdge; x <= rightEdge; x += resolution)
193 double slice = resolution * (buffer[
static_cast<int>(floor(x)) + cen_y * stats.width] - min);
202 int subPixelCenter = (
center->width / resolution) / 2;
205 TF = subPixels[subPixelCenter];
209 for (
int k = 1; k < subPixelCenter; k++)
211 TF += subPixels[subPixelCenter + k];
212 TF += subPixels[subPixelCenter - k];
220 center->HFR = (k - 1 + ((HF - lastTF) / (TF - lastTF)) * 2) * resolution;
231 starCenters.
append(center);
232 m_ImageData->setStarCenters(starCenters);
void append(QList< T > &&value)
void reserve(qsizetype size)
QTextStream & center(QTextStream &stream)
QFuture< T > run(Function function,...)
double toDouble(bool *ok) const const