Skip to content

Commit

Permalink
Use OpenCV's Gaussian blur
Browse files Browse the repository at this point in the history
This brings an enormous performance increase.

Also started saving the option for number of threads.
  • Loading branch information
BenJuan26 committed Oct 16, 2017
1 parent c6f15e6 commit 19e08e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 59 deletions.
24 changes: 9 additions & 15 deletions src/processing/imagestacker.cpp
Expand Up @@ -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;
Expand All @@ -37,42 +37,36 @@ 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) {
emit ProcessingError("Images must all be the same size.");
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();
Expand Down
47 changes: 5 additions & 42 deletions src/processing/stardetector.cpp
Expand Up @@ -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<float>(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<float>(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;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/mainwindow.cpp
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/ui/optionsdialog.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit 19e08e3

Please sign in to comment.