14#include <QtConcurrent>
16#include "fits_debug.h"
17#include "fitsgradientdetector.h"
22 FITSImage::Statistic
const &stats = m_ImageData->getStatistics();
23 switch (stats.dataType)
28 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<uint8_t>, boundary);
31 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<int16_t>, boundary);
34 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<uint16_t>, boundary);
37 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<int32_t>, boundary);
40 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<uint16_t>, boundary);
43 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<float>, boundary);
46 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<int64_t>, boundary);
49 return QtConcurrent::run(
this, &FITSGradientDetector::findSources<double>, boundary);
54bool FITSGradientDetector::findSources(
const QRect &boundary)
56 int subX =
qMax(0, boundary.
isNull() ? 0 : boundary.x());
57 int subY =
qMax(0, boundary.
isNull() ? 0 : boundary.y());
58 int subW = (boundary.
isNull() ? m_ImageData->width() : boundary.
width());
59 int subH = (boundary.
isNull() ? m_ImageData->height() : boundary.
height());
61 int BBP = m_ImageData->getBytesPerPixel();
63 uint16_t
dataWidth = m_ImageData->width();
66 uint32_t size = subW * subH;
67 uint32_t offset = subX + subY *
dataWidth;
70 auto * buffer =
new uint8_t[size *
BBP];
73 memcpy(buffer, m_ImageData->getImageBuffer(), size *
BBP);
77 uint8_t
const *
origDataPtr = m_ImageData->getImageBuffer();
80 for (
int height = subY; height < (subY + subH); height++)
90 FITSImage::Statistic stats;
93 stats.dataType = m_ImageData->getStatistics().dataType;
94 stats.bytesPerPixel = m_ImageData->getStatistics().bytesPerPixel;
95 stats.samples_per_channel = size;
136 for (
int y = 0; y < subH; y++)
138 for (
int x = 0; x < subW; x++)
140 int index = x + y * subW;
158 for (
auto key :
masses.keys())
181 int maxR =
qMin(subW - 1, subH - 1) / 2;
183 for (
int r =
maxR; r > 1; r--)
187 for (
float theta = 0; theta < 2 * M_PI; theta += (2 * M_PI) / 36.0)
223 const double resolution = 1.0 / 20.0;
233 const T *
origBuffer =
reinterpret_cast<T
const *
>(m_ImageData->getImageBuffer()) + offset;
277 starCenters.append(center);
278 m_ImageData->setStarCenters(starCenters);
295 FITSImage::Statistic
const &stats = data->getStatistics();
298 gradient.resize(stats.samples_per_channel);
299 direction.resize(stats.samples_per_channel);
301 for (
int y = 0; y < stats.height; y++)
303 size_t yOffset = y * stats.width;
304 const T *
grayLine =
reinterpret_cast<T
const *
>(data->getImageBuffer()) + yOffset;
312 for (
int x = 0; x < stats.width; x++)
314 int x_m1 = x < 1 ? x : x - 1;
315 int x_p1 = x >= stats.width - 1 ? x : x + 1;
359 if (a >= -22.5 && a < 22.5)
361 else if (a >= 22.5 && a < 67.5)
363 else if (a >= -67.5 && a < -22.5)
376 for (
int y = 1; y < height - 1; y++)
378 for (
int x = 1; x < width - 1; x++)
380 int index = x + y * width;
381 float val = gradient[index];
382 if (val > 0 &&
ids[index] == 0)
384 trace(width, height, ++
id, gradient,
ids, x, y);
396 int yOffset = y * width;
397 float *
cannyLine = image.data() + yOffset;
405 for (
int j = -1;
j < 2;
j++)
414 for (
int i = -1; i < 2; i++)
bool isNull() const const
QTextStream & center(QTextStream &stream)
QFuture< T > run(Function function,...)