13#include <QtConcurrent>
15#include "fits_debug.h"
16#include "fitsthresholddetector.h"
28 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
29 switch (stats.dataType)
32 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int16_t>, boundary);
35 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint16_t>, boundary);
38 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int32_t>, boundary);
41 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint32_t>, boundary);
44 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<float>, boundary);
47 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<int64_t>, boundary);
50 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<double>, boundary);
54 return QtConcurrent::run(
this, &FITSThresholdDetector::findOneStar<uint8_t>, boundary);
60bool FITSThresholdDetector::findOneStar(
const QRect &boundary)
const
62 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
64 int subX = boundary.
x();
65 int subY = boundary.
y();
66 int subW = subX + boundary.
width();
67 int subH = subY + boundary.
height();
69 float massX = 0, massY = 0, totalMass = 0;
71 auto * buffer =
reinterpret_cast<T
const *
>(m_ImageData->getImageBuffer());
73 double THRESHOLD_PERCENTAGE = getValue(
"THRESHOLD_PERCENTAGE", 120.0).
toDouble();
75 double threshold = stats.mean[0] * THRESHOLD_PERCENTAGE / 100.0;
77 for (
int y = subY; y < subH; y++)
79 for (
int x = subX; x < subW; x++)
81 T pixel = buffer[x + y * stats.width];
82 if (pixel > threshold)
91 qCDebug(KSTARS_FITS) <<
"FITS: Weighted Center is X: " << massX / totalMass <<
" Y: " << massY / totalMass;
95 center->x = massX / totalMass + 0.5;
96 center->y = massY / totalMass + 0.5;
100 int maxR = qMin(subW - 1, subH - 1) / 2;
103 double critical_threshold = threshold * 0.7;
104 double running_threshold = threshold;
106 while (running_threshold >= critical_threshold)
108 for (
int r = maxR; r > 1; r--)
112 for (
float theta = 0; theta < 2 * M_PI; theta += (2 * M_PI) / 10.0)
114 int testX =
center->x + std::cos(theta) * r;
115 int testY =
center->y + std::sin(theta) * r;
118 if (testX < subX || testX > subW || testY < subY || testY > subH)
121 if (buffer[testX + testY * stats.width] > running_threshold)
138 running_threshold -= running_threshold * 0.1;
151 double FSum = 0, HF = 0, TF = 0, min = stats.min[0];
152 const double resolution = 1.0 / 20.0;
154 int cen_y = qRound(
center->y);
162 for (
double x = leftEdge; x <= rightEdge; x += resolution)
165 double slice = resolution * (buffer[
static_cast<int>(floor(x)) + cen_y * stats.width] - min);
174 int subPixelCenter = (
center->width / resolution) / 2;
177 TF = subPixels[subPixelCenter];
181 for (
int k = 1; k < subPixelCenter; k++)
183 TF += subPixels[subPixelCenter + k];
184 TF += subPixels[subPixelCenter - k];
192 center->HFR = (k - 1 + ((HF - lastTF) / (TF - lastTF)) * 2) * resolution;
203 starCenters.
append(center);
204 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