13#include <QtConcurrent>
15#include "fitscentroiddetector.h"
16#include "fits_debug.h"
34bool FITSCentroidDetector::checkCollision(Edge *
s1, Edge *
s2)
const
55 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
56 switch (stats.dataType)
60 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<uint8_t const>, boundary);
63 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<int16_t const>, boundary);
66 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<uint16_t const>, boundary);
69 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<int32_t const>, boundary);
72 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<uint32_t const>, boundary);
75 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<float const>, boundary);
78 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<int64_t const>, boundary);
81 return QtConcurrent::run(
this, &FITSCentroidDetector::findSources<double const>, boundary);
87bool FITSCentroidDetector::findSources(
const QRect &boundary)
89 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
90 FITSMode
const m_Mode =
static_cast<FITSMode
>(m_ImageData->
property(
"mode").
toInt());
94 double JMIndex = getValue(
"JMINDEX", 100.0).
toDouble();
97 double threshold = 0, sum = 0,
avg = 0, min = 0;
102 auto * buffer =
reinterpret_cast<T
const *
>(m_ImageData->getImageBuffer());
108 if (JMIndex < DIFFUSE_THRESHOLD)
127 if (JMIndex < DIFFUSE_THRESHOLD)
133 if (threshold - min < 0)
150 qCDebug(
KSTARS_FITS) <<
"The threshold level is " << threshold <<
"(actual " << threshold - min
155 int subX, subY, subW, subH;
159 if (m_Mode == FITS_GUIDE || m_Mode == FITS_FOCUS)
162 subX = round(stats.width * 0.15);
163 subY = round(stats.height * 0.15);
164 subW = stats.width - subX;
165 subH = stats.height - subY;
180 subW = subX + boundary.
width();
181 subH = subY + boundary.
height();
185 for (
int i = subY; i < subH; i++)
189 for (
int j = subX;
j < subW;
j++)
191 pixVal = buffer[
j + (i * stats.width)] - min;
212 if (((buffer[
i_center + (i * stats.width)] - min) /
215 ((buffer[
i_center + (i * stats.width)] - min) /
220 <<
"Edge center is " << buffer[
i_center + (i * stats.width)] - min
223 << ((buffer[
i_center + (i * stats.width)] - min) /
225 <<
" located at X: " << center <<
" Y: " << i + 0.5;
227 auto * newEdge =
new Edge();
230 newEdge->y = i + 0.5;
231 newEdge->scanned = 0;
232 newEdge->val = buffer[
i_center + (i * stats.width)] - min;
237 edges.append(newEdge);
248 qCDebug(
KSTARS_FITS) <<
"Total number of edges found is: " <<
edges.count();
257 if (
edges.count() >= MAX_EDGE_LIMIT)
280 auto const greaterThan = [](Edge
const * a, Edge
const * b)
282 return a->sum > b->sum;
284 std::sort(
edges.begin(),
edges.end(), greaterThan);
288 for (
int i = 0; i <
edges.count(); i++)
290 qCDebug(
KSTARS_FITS) <<
"# " << i <<
" Edge at (" <<
edges[i]->x <<
"," <<
edges[i]->y <<
") With a value of "
291 <<
edges[i]->val <<
" and width of " <<
edges[i]->width <<
" pixels. with sum " <<
edges[i]->sum;
294 if (
edges[i]->scanned == 1)
296 qCDebug(
KSTARS_FITS) <<
"Skipping check for center " << i <<
" because it was already counted";
300 qCDebug(
KSTARS_FITS) <<
"Investigating edge # " << i <<
" now ...";
315 for (
int j = 0;
j <
edges.count();
j++)
341 if (
edges.count() < LOW_EDGE_CUTOFF_1)
343 if (
edges.count() < LOW_EDGE_CUTOFF_2)
404 qCDebug(
KSTARS_FITS) <<
"Stopping at TF " <<
TF <<
" after #" <<
k <<
" pixels.";
419 qCDebug(
KSTARS_FITS) <<
"HFR for this center is " <<
rCenter->HFR <<
" pixels and the total flux is " <<
FSum;
425 if (starCenters.count() > 1 && m_Mode != FITS_FOCUS)
430 for (
auto ¢er : starCenters)
433 sdev = (std::sqrt(
lsum / (starCenters.count() - 1))) * 4;
436 foreach (Edge * center, starCenters)
438 starCenters.removeOne(center);
444 m_ImageData->setStarCenters(starCenters);
QVariant property(const char *name) const const
bool isNull() const const
QTextStream & center(QTextStream &stream)
QFuture< T > run(Function function,...)
double toDouble(bool *ok) const const
int toInt(bool *ok) const const