From 0fa09a775bd9febd2bf64d8fa9ad4ad0cab28dc1 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 20 Nov 2015 12:48:05 +0100 Subject: [PATCH] [TASK] Allow loading a reference image, add indicators for its stats. --- imageviewer-qt4.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++-- imageviewer-qt4.h | 6 +++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index c5e2c73..ab854ad 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -47,6 +47,7 @@ ImageViewer::ImageViewer() { original = NULL; working_copy = NULL; + histogramm_reference = NULL; startLogging(); generateMainGui(); renewLogging(); @@ -422,7 +423,15 @@ void ImageViewer::generateControlPanels() { task_tab_widget2 = new QWidget(); task_tab2 = new QVBoxLayout(); task_tab_widget2->setLayout(task_tab2); - + + reference_histogramm_label = new QLabel(); + reference_histogramm_label->setBackgroundRole(QPalette::Base); + reference_histogramm_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + reference_histogramm_label->setScaledContents(false); + + reference_stats = new QLabel(); + reference_stats->setText("Stats for reference image will be shown here."); + original_histogramm_label = new QLabel(); original_histogramm_label->setBackgroundRole(QPalette::Base); original_histogramm_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -460,7 +469,10 @@ void ImageViewer::generateControlPanels() { contrast_percentile_slider->setMaximum(100); contrast_percentile_slider->setValue(10); QObject::connect(contrast_percentile_slider, SIGNAL(valueChanged(int)), this, SLOT(robustAutomaticContrastAdaption(int))); - + + task_tab2->addWidget(new QLabel("Reference image")); + task_tab2->addWidget(reference_stats); + task_tab2->addWidget(reference_histogramm_label); task_tab2->addWidget(new QLabel("Original image")); task_tab2->addWidget(original_stats); task_tab2->addWidget(original_histogramm_label); @@ -481,6 +493,11 @@ void ImageViewer::generateControlPanels() { task_tab_widget3 = new QWidget(); task_tab3 = new QVBoxLayout(); task_tab_widget3->setLayout(task_tab3); + + reference_histogramm_cumulative_label = new QLabel(); + reference_histogramm_cumulative_label->setBackgroundRole(QPalette::Base); + reference_histogramm_cumulative_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + reference_histogramm_cumulative_label->setScaledContents(false); original_histogramm_cumulative_label = new QLabel(); original_histogramm_cumulative_label->setBackgroundRole(QPalette::Base); @@ -495,6 +512,8 @@ void ImageViewer::generateControlPanels() { linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (basic)"); QObject::connect(linear_histogramm_adaption, SIGNAL(clicked()), this, SLOT(linearHistogrammAdaption())); + task_tab3->addWidget(new QLabel("Reference image")); + task_tab3->addWidget(reference_histogramm_cumulative_label); task_tab3->addWidget(new QLabel("Original image")); task_tab3->addWidget(original_histogramm_cumulative_label); task_tab3->addWidget(new QLabel("Working copy")); @@ -627,6 +646,36 @@ void ImageViewer::open() { } } +/** + * Simply load another image to provide reference for some operations. + * @brief ImageViewer::openReference + */ +void ImageViewer::openReference() { + if(histogramm_reference != NULL) { + delete histogramm_reference; + histogramm_reference = NULL; + } + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Histogramm Reference File"), QDir::currentPath()); + if(!fileName.isEmpty()) { + histogramm_reference = new LazyImage(new QImage(fileName)); + if(histogramm_reference->getImage()->isNull()) { + QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName)); + return; + } + + if(histogramm_reference->getImage() != NULL) { + histogramm_reference->updateStatistics(); + QString result = QString("Intensity: Average: %1, Variance: %2").arg(histogramm_reference->getIntensityAverage()).arg(histogramm_reference->getIntensityVariance()); + reference_stats->setText(result); + reference_histogramm_label->setPixmap(QPixmap::fromImage(*(histogramm_reference->getHistogrammNormalImage()))); + reference_histogramm_cumulative_label->setPixmap(QPixmap::fromImage(*(histogramm_reference->getHistogrammCumulativeImage()))); + } + + logFile << "Referenzbild geladen: " << fileName.toStdString().c_str() << std::endl; + renewLogging(); + } +} + void ImageViewer::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); centralwidget->setMinimumWidth(width()); @@ -680,6 +729,10 @@ void ImageViewer::createActions() { openAct->setShortcut(tr("Ctrl+O")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + openHistAct = new QAction(tr("Open &Reference..."), this); + openHistAct->setShortcut(tr("Ctrl+O")); + connect(openHistAct, SIGNAL(triggered()), this, SLOT(openReference())); + printAct = new QAction(tr("&Print..."), this); printAct->setShortcut(tr("Ctrl+P")); printAct->setEnabled(false); @@ -720,6 +773,7 @@ void ImageViewer::createActions() { void ImageViewer::createMenus() { fileMenu = new QMenu(tr("&File"), this); fileMenu->addAction(openAct); + fileMenu->addAction(openHistAct); fileMenu->addAction(printAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index 2ad91ed..3c49e95 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -88,8 +88,10 @@ class ImageViewer : public QMainWindow { QWidget* task_tab_widget2; QVBoxLayout* task_tab2; + QLabel* reference_stats; QLabel* original_stats; QLabel* stats; + QLabel* reference_histogramm_label; QLabel* original_histogramm_label; QLabel* histogramm_label; QPushButton* analyze_image; @@ -103,6 +105,7 @@ class ImageViewer : public QMainWindow { QWidget* task_tab_widget3; QVBoxLayout* task_tab3; + QLabel* reference_histogramm_cumulative_label; QLabel* original_histogramm_cumulative_label; QLabel* histogramm_cumulative_label; @@ -111,6 +114,7 @@ class ImageViewer : public QMainWindow { // "My" space for storing data/results LazyImage* original; LazyImage* working_copy; + LazyImage* histogramm_reference; private slots: // Custom slots @@ -127,6 +131,7 @@ class ImageViewer : public QMainWindow { void linearHistogrammAdaption(); void open(); + void openReference(); void print(); void zoomIn(); void zoomOut(); @@ -175,6 +180,7 @@ class ImageViewer : public QMainWindow { #endif QAction *openAct; + QAction *openHistAct; QAction *printAct; QAction *exitAct; QAction *zoomInAct;