Draw circles around peaks
This commit is contained in:
+49
-27
@@ -7,10 +7,36 @@
|
||||
#include <math.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
|
||||
{
|
||||
public:
|
||||
virtual ~RawImageAbs(){}
|
||||
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>
|
||||
@@ -24,28 +50,6 @@ class RawImage : public RawImageAbs
|
||||
return c>=d;
|
||||
}
|
||||
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()
|
||||
{
|
||||
m_width = m_height = 0;
|
||||
@@ -122,7 +126,7 @@ public:
|
||||
if(y>=m_height)y=0;
|
||||
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;
|
||||
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, 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());
|
||||
tmpPeaks.resize(10000);
|
||||
int num = tmpPeaks.size();
|
||||
std::sort(tmpPeaks.begin(), tmpPeaks.end());
|
||||
tmpPeaks.resize(std::min(num, 10000));
|
||||
uint32_t d = distance*distance;
|
||||
for(const Peak &p : tmpPeaks)
|
||||
{
|
||||
@@ -156,9 +161,10 @@ public:
|
||||
}
|
||||
if(pass)
|
||||
{
|
||||
peaks.append(p);
|
||||
peaks.push_back(p);
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
void medianFilter()
|
||||
{
|
||||
@@ -178,6 +184,22 @@ public:
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user