Make median filter parallel

This commit is contained in:
2019-09-28 13:05:07 +02:00
parent eb307ea091
commit 759383c4a1
3 changed files with 15 additions and 8 deletions
+3 -1
View File
@@ -13,7 +13,9 @@ TEMPLATE = app
CONFIG += c++11 CONFIG += c++11
LIBS += -lraw -lexif -lcfitsio QMAKE_CXXFLAGS += -fopenmp
LIBS += -lraw -lexif -lcfitsio -fopenmp
SOURCES += main.cpp\ SOURCES += main.cpp\
mainwindow.cpp \ mainwindow.cpp \
+8 -3
View File
@@ -26,7 +26,7 @@ void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag)
} }
} }
void drawPeaks(QImage &img, const std::vector<Peak> &peaks, bool half) void drawPeaks(QImage &img, const std::vector<Peak> &peaks)
{ {
QPixmap pix = QPixmap::fromImage(img); QPixmap pix = QPixmap::fromImage(img);
QPainter painter(&pix); QPainter painter(&pix);
@@ -222,9 +222,11 @@ void LoadRunable::run()
QImage img; QImage img;
RawImageAbs *rawImage = nullptr; RawImageAbs *rawImage = nullptr;
bool raw = false;
if(m_file.endsWith(".CR2", Qt::CaseInsensitive)) if(m_file.endsWith(".CR2", Qt::CaseInsensitive))
{ {
loadRAW(m_file, info, m_analyzeLevel != None ? &rawImage : nullptr, &img); loadRAW(m_file, info, m_analyzeLevel != None ? &rawImage : nullptr, &img);
raw = true;
} }
else if(m_file.endsWith(".FIT", Qt::CaseInsensitive)) else if(m_file.endsWith(".FIT", Qt::CaseInsensitive))
{ {
@@ -244,7 +246,7 @@ void LoadRunable::run()
} }
} }
if(m_analyzeLevel >= Statistics) if(rawImage && m_analyzeLevel >= Statistics)
{ {
uint64_t mean, median, min, max; uint64_t mean, median, min, max;
double stdDev; double stdDev;
@@ -258,10 +260,13 @@ void LoadRunable::run()
if(m_analyzeLevel >= Peaks) if(m_analyzeLevel >= Peaks)
{ {
std::vector<Peak> peaks; std::vector<Peak> peaks;
if(raw) {
rawImage->quarter(); rawImage->quarter();
qDebug() << "quarter" << timer.restart();
}
rawImage->medianFilter(); rawImage->medianFilter();
int numPeaks = rawImage->findPeaks(median+stdDev, 20, peaks); int numPeaks = rawImage->findPeaks(median+stdDev, 20, peaks);
drawPeaks(img, peaks, true); drawPeaks(img, peaks);
info.append(StringPair(QObject::tr("Peaks"), QString::number(numPeaks))); info.append(StringPair(QObject::tr("Peaks"), QString::number(numPeaks)));
info.append(StringPair(QObject::tr("Peaks draw"), QString::number(peaks.size()))); info.append(StringPair(QObject::tr("Peaks draw"), QString::number(peaks.size())));
} }
+3 -3
View File
@@ -169,7 +169,7 @@ public:
{ {
std::vector<T> tmp; std::vector<T> tmp;
tmp.resize(m_width*m_height); tmp.resize(m_width*m_height);
size_t d=0; #pragma omp parallel for
for(uint32_t y=0;y<m_height;y++) for(uint32_t y=0;y<m_height;y++)
{ {
for(uint32_t x=0;x<m_width;x++) for(uint32_t x=0;x<m_width;x++)
@@ -177,8 +177,8 @@ public:
T array[9] = { pixel(x-1, y-1), pixel(x, y-1), pixel(x+1, y-1), T array[9] = { pixel(x-1, y-1), pixel(x, y-1), pixel(x+1, y-1),
pixel(x-1, y), pixel(x, y), pixel(x+1, y), pixel(x-1, y), pixel(x, y), pixel(x+1, y),
pixel(x-1, y+1), pixel(x, y+1), pixel(x+1, y+1)}; pixel(x-1, y+1), pixel(x, y+1), pixel(x+1, y+1)};
std::partial_sort(std::begin(array), array+5, std::end(array)); std::nth_element(std::begin(array), array+4, std::end(array));
tmp[d++] = array[4]; tmp[y*m_width+x] = array[4];
} }
} }
m_img = std::move(tmp); m_img = std::move(tmp);