From 19e08e3570a5b5204253cc4904211ed44f32730e Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Mon, 16 Oct 2017 19:22:25 -0400 Subject: [PATCH] Use OpenCV's Gaussian blur This brings an enormous performance increase. Also started saving the option for number of threads. --- src/processing/imagestacker.cpp | 24 +++++++---------- src/processing/stardetector.cpp | 47 ++++----------------------------- src/ui/mainwindow.cpp | 1 + src/ui/optionsdialog.cpp | 6 +++-- 4 files changed, 19 insertions(+), 59 deletions(-) diff --git a/src/processing/imagestacker.cpp b/src/processing/imagestacker.cpp index add61c2..9bb6a45 100644 --- a/src/processing/imagestacker.cpp +++ b/src/processing/imagestacker.cpp @@ -11,7 +11,7 @@ ImageStacker::ImageStacker(QObject *parent) : QObject(parent) int ImageStacker::GetTotalOperations() { - int ops = target_image_file_names_.length() + 1; + int ops = target_image_file_names_.length() + 4; if (use_bias_) ops += 1; if (use_darks_) ops += 1; @@ -37,7 +37,9 @@ void ImageStacker::Process(int tolerance, int threads) { } cancel_ = false; - emit UpdateProgress(tr("Checking image sizes..."), 0); + current_operation_ = 1; + total_operations_ = GetTotalOperations(); + emit UpdateProgress(tr("Checking image sizes..."), 100 * current_operation_++ / total_operations_); int err = ValidateImageSizes(); if (err) { @@ -45,34 +47,26 @@ void ImageStacker::Process(int tolerance, int threads) { return; } - current_operation_ = 1; - total_operations_ = GetTotalOperations(); - cv::Mat masterDark, masterDarkFlat, masterFlat, masterBias; if (use_bias_) { - emit UpdateProgress(tr("Stacking bias frames..."), 100 * current_operation_ / total_operations_); + emit UpdateProgress(tr("Stacking bias frames..."), 100 * current_operation_++ / total_operations_); masterBias = StackBias(bias_frame_file_names_); - current_operation_++; } if (use_darks_) { - emit UpdateProgress(tr("Stacking dark frames..."), 100 * current_operation_ / total_operations_); + emit UpdateProgress(tr("Stacking dark frames..."), 100 * current_operation_++ / total_operations_); masterDark = StackDarks(dark_frame_file_names_, masterBias); - current_operation_++; } if (use_dark_flats_) { - emit UpdateProgress(tr("Stacking dark flat frames..."), 100 * current_operation_ / total_operations_); + emit UpdateProgress(tr("Stacking dark flat frames..."), 100 * current_operation_++ / total_operations_); masterDarkFlat = StackDarkFlats(dark_flat_frame_file_names_, masterBias); - current_operation_++; } if (use_flats_) { - emit UpdateProgress(tr("Stacking flat frames..."), 100 * current_operation_ / total_operations_); + emit UpdateProgress(tr("Stacking flat frames..."), 100 * current_operation_++ / total_operations_); masterFlat = StackFlats(flat_frame_file_names_, masterDarkFlat, masterBias); - current_operation_++; } - emit UpdateProgress(tr("Stacking light frames..."), 100 * current_operation_ / total_operations_); - current_operation_++; + emit UpdateProgress(tr("Stacking light frames..."), 100 * current_operation_++ / total_operations_); ref_image_ = GetCalibratedImage(ref_image_file_name_, masterDark , masterFlat, masterBias); working_image_ = ref_image_.clone(); diff --git a/src/processing/stardetector.cpp b/src/processing/stardetector.cpp index 6cdce04..03fb43d 100644 --- a/src/processing/stardetector.cpp +++ b/src/processing/stardetector.cpp @@ -77,50 +77,13 @@ cv::Mat StarDetector::GenerateSkyBackground(cv::Mat image) { cv::Mat result = image.clone(); cv::resize(result, result, cv::Size(result.cols/8, result.rows/8)); - cv::medianBlur(result, result, 5); - cv::resize(result, result, cv::Size(image.cols, image.rows)); - - float *buffer; - buffer = new float[result.cols]; - int filter_size = 16; - - for (int y = 0; y < result.rows; y++) { - float val = 0.0; - for (int x = - (filter_size - 1) / 2 - 1 ; x < filter_size / 2 ; x++) - val += GetExtendedPixelValue(result, x, y); - - for (int x = 0 ; x < result.cols ; x++) { - val -= GetExtendedPixelValue(result, x - (filter_size - 1) / 2 - 1, y); - val += GetExtendedPixelValue(result, x + filter_size / 2, y); - - buffer[x] = val / (float)filter_size; - } - - for (int x = 0 ; x < result.cols ; x++) - result.at(y, x) = buffer[x]; - } - delete [] buffer; - - buffer = new float[result.rows]; - - for (int x = 0 ; x < result.cols ; x++) { - float val = 0.0; - for (int y = - (filter_size - 1) / 2 - 1 ; y < filter_size / 2 ; y++) - val += GetExtendedPixelValue(result, x, y); - - for (int y = 0 ; y < result.rows ; y++) { - val -= GetExtendedPixelValue(result, x, y - (filter_size - 1) / 2 - 1); - val += GetExtendedPixelValue(result, x, y + filter_size / 2); - - buffer[y] = val / (float)filter_size; - } - - for (int y = 0 ; y < result.rows ; y++) - result.at(y, x) = buffer[y]; - } + int medianFilterSize = 5; + cv::medianBlur(result, result, medianFilterSize); + cv::resize(result, result, cv::Size(image.cols, image.rows)); - delete [] buffer; + int gaussianFilterSize = 31; + cv::GaussianBlur(result, result, cv::Size(gaussianFilterSize, gaussianFilterSize), 0); return result; } diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index f37aa55..62c8919 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -280,6 +280,7 @@ void MainWindow::handleButtonStack() { settings.setValue("StarDetector/thresholdCoeff", thresh); int threads = dialog->GetThreads(); + settings.setValue("ImageStacker/threads", threads); QString saveFilePath = dialog->GetPath(); delete dialog; diff --git a/src/ui/optionsdialog.cpp b/src/ui/optionsdialog.cpp index 79f168e..7248924 100644 --- a/src/ui/optionsdialog.cpp +++ b/src/ui/optionsdialog.cpp @@ -17,9 +17,11 @@ OptionsDialog::OptionsDialog(QWidget *parent) : connect(ui->buttonDetectStars, SIGNAL(released()), this, SLOT(handleButtonDetectStars())); - ui->spinboxThreads->setValue(QThread::idealThreadCount()); - QSettings settings("OpenSkyStacker", "OpenSkyStacker"); + + int threads = settings.value("ImageStacker/threads", QThread::idealThreadCount()).toInt(); + ui->spinboxThreads->setValue(threads); + int thresh = settings.value("StarDetector/thresholdCoeff", 20).toInt(); valuesChanged(thresh); }