From 282fa987eda54c1b0f10cf2ecd6ea4f428a3a3fa Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 23 Nov 2015 13:01:11 +0100 Subject: [PATCH] [!!! TASK] Begin implementing partial linear histogramm adaption - broken; --- imageviewer-qt4.cpp | 48 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index accf3f0..ddf05d4 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -371,19 +371,53 @@ void ImageViewer::linearHistogrammAdaption(void) { void ImageViewer::partialLinearHistogrammAdaption() { logFile << "Doing partial linear histogramm adaption ..." << std::endl; renewLogging(); - - // TODO - // Get cumulative histogramm from reference image + double* reference_histogramm = histogramm_reference->getRelativeCumulativeIntensityHistogramm(); + // Split [0,255] into n parts (slider) - // fetch the values for the n parts, do some math and create the histogramm map + int number_parts = partial_adaption_pieces_slider->value(); + int* parts = (int*) malloc(number_parts*sizeof(int)); + for(int i=0; i<=number_parts; i++) { + parts[i] = qRound((255.0/number_parts)*i); + } + + // Create + double* histogramm_map = (double*) malloc(256*sizeof(double)); + for(int i=0; i<=number_parts; i++) { + int current_n = parts[i]; + if(current_n == 0) continue; // First part is always at zero! + int last_n = parts[i-1]; + int delta_n = current_n - last_n; + double delta_i = reference_histogramm[current_n] - reference_histogramm[last_n]; + double m = delta_i / delta_n; + double offset = histogramm_map[last_n]; + // Fill in the blanks + for(int j=last_n; j<=current_n; j++) { + int delta_n = j - last_n; + histogramm_map[j] = (offset + delta_n*m); + logFile << j << " -> " << histogramm_map[j] << std::endl; + } + } // Apply the histogramm map (see succeeding Histogramm Adaption) - - - + /* + int h, s, l; + 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 = qRound(histogramm_map[l] * (255/pixels)); + color.setHsl(h, s, l); + working_copy->getImage()->setPixel(x, y, color.rgb()); + } + }*/ + // Done. + free(histogramm_map); + free(parts); logFile << "done." << std::endl; renewLogging(); + updateImageDisplay(); } /**