diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index d89724e..dcdc50d 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -316,6 +316,33 @@ void ImageViewer::robustAutomaticContrastAdaption(int c_param) { renewLogging(); } +/** + * Do a very basic, linear histogramm adaption. + * + * @brief ImageViewer::linearHistogrammAdaption + */ +void ImageViewer::linearHistogrammAdaption(void) { + logFile << "Doing linear histogramm adaption ..." << std::endl; + renewLogging(); + int h, s, l; + int* ach = original->getAbsoluteCumulativeIntensityHistogramm(); + int pixels = working_copy->getImage()->width()*working_copy->getImage()->height(); + for(int x=0; xgetImage()->width(); x++) { + for(int y=0; ygetImage()->height(); y++) { + QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); + color.getHsl(&h, &s, &l); + + l = (int) qFloor(ach[l] * (255.0/pixels)); + + color.setHsl(h, s, l); + working_copy->getImage()->setPixel(x, y, color.rgb()); + } + } + updateImageDisplay(); + logFile << "done." << std::endl; + renewLogging(); +} + /**************************************************************************************** * @@ -408,8 +435,7 @@ void ImageViewer::generateControlPanels() { contrast_percentile_slider = new QSlider(Qt::Horizontal); contrast_percentile_slider->setMinimum(0); contrast_percentile_slider->setMaximum(100); - contrast_percentile_slider->setValue(10); - + contrast_percentile_slider->setValue(10); QObject::connect(contrast_percentile_slider, SIGNAL(valueChanged(int)), this, SLOT(robustAutomaticContrastAdaption(int))); task_tab2->addWidget(new QLabel("Original image")); @@ -443,10 +469,14 @@ void ImageViewer::generateControlPanels() { histogramm_cumulative_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); histogramm_cumulative_label->setScaledContents(false); + 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("Original image")); task_tab3->addWidget(original_histogramm_cumulative_label); task_tab3->addWidget(new QLabel("Working copy")); task_tab3->addWidget(histogramm_cumulative_label); + task_tab3->addWidget(linear_histogramm_adaption); tabWidget->addTab(task_tab_widget3, "Task #3"); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index 5f92307..4e5e0e4 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -105,6 +105,8 @@ class ImageViewer : public QMainWindow { QLabel* original_histogramm_cumulative_label; QLabel* histogramm_cumulative_label; + QPushButton* linear_histogramm_adaption; + // "My" space for storing data/results LazyImage* original; LazyImage* working_copy; @@ -120,6 +122,7 @@ class ImageViewer : public QMainWindow { void convertToMonochrome(); void resetWorkingCopy(); void robustAutomaticContrastAdaption(int c_param); + void linearHistogrammAdaption(); void open(); void print(); diff --git a/lazy_image.cpp b/lazy_image.cpp index 4e0c836..503b208 100644 --- a/lazy_image.cpp +++ b/lazy_image.cpp @@ -17,6 +17,7 @@ class LazyImage { QImage* histogramm_cumulative_image; double histogramm_relative_intensity[256]; int histogramm_absolute_intensity[256]; + int histogramm_absolute_cumulative_intensity[256]; int intensity_average; int intensity_variance; @@ -25,6 +26,7 @@ class LazyImage { for(int i=0; i<256; i++) { histogramm_relative_intensity[i] = 0; histogramm_absolute_intensity[i] = 0; + histogramm_absolute_cumulative_intensity[i] = 0; } // Count all the brightness values for(int x=0; ximg->width(); x++) { @@ -35,11 +37,15 @@ class LazyImage { int intensity = this->calcIntensity(r, g, b); histogramm_absolute_intensity[intensity] += 1; } - } - // Calculate relative histogramm + } + + // Calculate relative histogramm and absolute cumulative histogramm int pixels = this->img->width()*this->img->height(); + int sum = 0; for(int i=0; i<256; i++) { histogramm_relative_intensity[i] = (((double) histogramm_absolute_intensity[i])/((double) pixels)); + sum += histogramm_absolute_intensity[i]; + histogramm_absolute_cumulative_intensity[i] = sum; } }; @@ -166,7 +172,11 @@ class LazyImage { int* getAbsoluteIntensityHistogramm(void) { return this->histogramm_absolute_intensity; }; - + + int* getAbsoluteCumulativeIntensityHistogramm(void) { + return this->histogramm_absolute_cumulative_intensity; + }; + double* getRelativeIntensityHistogramm(void) { return this->histogramm_relative_intensity; };