Draw circles around peaks
This commit is contained in:
+27
-1
@@ -3,6 +3,7 @@
|
|||||||
#include <libraw/libraw.h>
|
#include <libraw/libraw.h>
|
||||||
#include "imageinfo.h"
|
#include "imageinfo.h"
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QPainter>
|
||||||
#include <libexif/exif-data.h>
|
#include <libexif/exif-data.h>
|
||||||
#include <fitsio2.h>
|
#include <fitsio2.h>
|
||||||
#include "rawimage.h"
|
#include "rawimage.h"
|
||||||
@@ -25,6 +26,18 @@ void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawPeaks(QImage &img, const std::vector<Peak> &peaks, bool half)
|
||||||
|
{
|
||||||
|
QPixmap pix = QPixmap::fromImage(img);
|
||||||
|
QPainter painter(&pix);
|
||||||
|
painter.setPen(Qt::red);
|
||||||
|
for(auto peak : peaks)
|
||||||
|
{
|
||||||
|
painter.drawEllipse(QPoint(peak.x(), peak.y()), 5, 5);
|
||||||
|
}
|
||||||
|
img = pix.toImage();
|
||||||
|
}
|
||||||
|
|
||||||
bool loadRAW(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qimage)
|
bool loadRAW(QString path, ImageInfoData &info, RawImageAbs **image, QImage *qimage)
|
||||||
{
|
{
|
||||||
if(!image && !qimage)
|
if(!image && !qimage)
|
||||||
@@ -231,7 +244,7 @@ void LoadRunable::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rawImage)
|
if(m_analyzeLevel >= Statistics)
|
||||||
{
|
{
|
||||||
uint64_t mean, median, min, max;
|
uint64_t mean, median, min, max;
|
||||||
double stdDev;
|
double stdDev;
|
||||||
@@ -241,7 +254,20 @@ void LoadRunable::run()
|
|||||||
info.append(StringPair(QObject::tr("Median"), QString::number(median)));
|
info.append(StringPair(QObject::tr("Median"), QString::number(median)));
|
||||||
info.append(StringPair(QObject::tr("Minimum"), QString::number(min)));
|
info.append(StringPair(QObject::tr("Minimum"), QString::number(min)));
|
||||||
info.append(StringPair(QObject::tr("Maximum"), QString::number(max)));
|
info.append(StringPair(QObject::tr("Maximum"), QString::number(max)));
|
||||||
|
|
||||||
|
if(m_analyzeLevel >= Peaks)
|
||||||
|
{
|
||||||
|
std::vector<Peak> peaks;
|
||||||
|
rawImage->quarter();
|
||||||
|
rawImage->medianFilter();
|
||||||
|
int numPeaks = rawImage->findPeaks(median+stdDev, 20, peaks);
|
||||||
|
drawPeaks(img, peaks, true);
|
||||||
|
info.append(StringPair(QObject::tr("Peaks"), QString::number(numPeaks)));
|
||||||
|
info.append(StringPair(QObject::tr("Peaks draw"), QString::number(peaks.size())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rawImage)delete rawImage;
|
||||||
|
|
||||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info));
|
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info));
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-27
@@ -7,10 +7,36 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
|
class Peak
|
||||||
|
{
|
||||||
|
uint32_t m_v;
|
||||||
|
uint32_t m_x,m_y;
|
||||||
|
public:
|
||||||
|
Peak() : m_v(0), m_x(0), m_y(0) {}
|
||||||
|
Peak(uint32_t v, uint32_t x, uint32_t y) : m_v(v), m_x(x), m_y(y) {}
|
||||||
|
uint32_t v() const { return m_v; }
|
||||||
|
uint32_t x() const { return m_x; }
|
||||||
|
uint32_t y() const { return m_y; }
|
||||||
|
double distance(const Peak &d) const
|
||||||
|
{
|
||||||
|
uint32_t dx = m_x-d.m_x;
|
||||||
|
uint32_t dy = m_y-d.m_y;
|
||||||
|
return dx*dx + dy*dy;
|
||||||
|
}
|
||||||
|
bool operator <(const Peak &d) const
|
||||||
|
{
|
||||||
|
return m_v > d.m_v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class RawImageAbs
|
class RawImageAbs
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~RawImageAbs(){}
|
||||||
virtual bool imageStats(uint64_t *mean, double *stdDev, uint64_t *median, uint64_t *min, uint64_t *max) const = 0;
|
virtual bool imageStats(uint64_t *mean, double *stdDev, uint64_t *median, uint64_t *min, uint64_t *max) const = 0;
|
||||||
|
virtual int findPeaks(uint64_t background, double distance, std::vector<Peak> &peaks) const = 0;
|
||||||
|
virtual void medianFilter() = 0;
|
||||||
|
virtual void quarter() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -24,28 +50,6 @@ class RawImage : public RawImageAbs
|
|||||||
return c>=d;
|
return c>=d;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
class Peak
|
|
||||||
{
|
|
||||||
T m_v;
|
|
||||||
uint32_t m_x,m_y;
|
|
||||||
public:
|
|
||||||
Peak() : m_v(0), m_x(0), m_y(0) {}
|
|
||||||
Peak(T v, uint32_t x, uint32_t y) : m_v(v), m_x(x), m_y(y) {}
|
|
||||||
T v() const { return m_v; }
|
|
||||||
uint32_t x() const { return m_x; }
|
|
||||||
uint32_t y() const { return m_y; }
|
|
||||||
double distance(const Peak &d) const
|
|
||||||
{
|
|
||||||
uint32_t dx = m_x-d.m_x;
|
|
||||||
uint32_t dy = m_y-d.m_y;
|
|
||||||
return dx*dx + dy*dy;
|
|
||||||
}
|
|
||||||
bool operator <(const Peak &d) const
|
|
||||||
{
|
|
||||||
return m_v > d.m_v;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RawImage()
|
RawImage()
|
||||||
{
|
{
|
||||||
m_width = m_height = 0;
|
m_width = m_height = 0;
|
||||||
@@ -122,7 +126,7 @@ public:
|
|||||||
if(y>=m_height)y=0;
|
if(y>=m_height)y=0;
|
||||||
return m_img[y*m_width+x];
|
return m_img[y*m_width+x];
|
||||||
}
|
}
|
||||||
void findPeaks(T background, double distance, std::vector<Peak> &peaks, T sigma) const
|
int findPeaks(uint64_t background, double distance, std::vector<Peak> &peaks) const
|
||||||
{
|
{
|
||||||
std::vector<Peak> tmpPeaks;
|
std::vector<Peak> tmpPeaks;
|
||||||
const int r = 1;
|
const int r = 1;
|
||||||
@@ -135,13 +139,14 @@ public:
|
|||||||
checkPixel(c, o+r, i-r) && checkPixel(c, o-r, i) && checkPixel(c, o+r, i)
|
checkPixel(c, o+r, i-r) && checkPixel(c, o-r, i) && checkPixel(c, o+r, i)
|
||||||
&& checkPixel(c, o-r, i+r) && checkPixel(c, o, i+r) && checkPixel(c, o+r, i+r))
|
&& checkPixel(c, o-r, i+r) && checkPixel(c, o, i+r) && checkPixel(c, o+r, i+r))
|
||||||
{
|
{
|
||||||
tmpPeaks.append(Peak(c, o, i));
|
tmpPeaks.push_back(Peak(c, o, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::qsort(tmpPeaks.begin(), tmpPeaks.end());
|
int num = tmpPeaks.size();
|
||||||
tmpPeaks.resize(10000);
|
std::sort(tmpPeaks.begin(), tmpPeaks.end());
|
||||||
|
tmpPeaks.resize(std::min(num, 10000));
|
||||||
uint32_t d = distance*distance;
|
uint32_t d = distance*distance;
|
||||||
for(const Peak &p : tmpPeaks)
|
for(const Peak &p : tmpPeaks)
|
||||||
{
|
{
|
||||||
@@ -156,9 +161,10 @@ public:
|
|||||||
}
|
}
|
||||||
if(pass)
|
if(pass)
|
||||||
{
|
{
|
||||||
peaks.append(p);
|
peaks.push_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return num;
|
||||||
}
|
}
|
||||||
void medianFilter()
|
void medianFilter()
|
||||||
{
|
{
|
||||||
@@ -178,6 +184,22 @@ public:
|
|||||||
}
|
}
|
||||||
m_img = std::move(tmp);
|
m_img = std::move(tmp);
|
||||||
}
|
}
|
||||||
|
void quarter()
|
||||||
|
{
|
||||||
|
std::vector<T> tmp;
|
||||||
|
tmp.resize(m_width*m_height);
|
||||||
|
uint32_t d = 0;
|
||||||
|
for(uint32_t i=0;i<m_height;i+=2)
|
||||||
|
{
|
||||||
|
for(uint32_t o=0;o<m_width;o+=2)
|
||||||
|
{
|
||||||
|
tmp[d++] = m_img[i*m_width+o];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_img = tmp;
|
||||||
|
m_width /= 2;
|
||||||
|
m_height /= 2;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RAWIMAGE_H
|
#endif // RAWIMAGE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user