diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index 7f56a9c..976f4f5 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -384,8 +384,7 @@ void ImageViewer::partialLinearHistogrammAdaption() { } // Create histogramm map - // This will point every new brightness index to the old double value - // from the reference histogramm. (array with double index, but the other way around :/ ) + // This represents the new cumulative histogramm built of linear parts double* histogramm_map = (double*) malloc(256*sizeof(double)); for(int i=0; i<=number_parts; i++) { int current_n = parts[i]; @@ -395,7 +394,7 @@ void ImageViewer::partialLinearHistogrammAdaption() { double delta_i = reference_histogramm[current_n] - reference_histogramm[last_n]; double m = delta_i / delta_n; double offset = histogramm_map[last_n]; - // Calculate the mapping values + // Calculate the new cumulative values for(int j=last_n; j<=current_n; j++) { int delta_n = j - last_n; histogramm_map[j] = (offset + delta_n*m); @@ -404,14 +403,12 @@ void ImageViewer::partialLinearHistogrammAdaption() { } // Build up the brightness map to apply on the image - // (basically reversing and applying the histogramm map) + // (basically inversing the histogramm map) int* brightness_map = (int*) malloc(256*sizeof(int)); + int j=0; for(int i=0; i<256; i++) { - double old_brightness_occurrence = reference_histogramm[i]; - int j = 0; - for(j=0; j<256; j++) { - if(old_brightness_occurrence < histogramm_map[j]) break; - } + double old_cumulative_brightness = reference_histogramm[i]; + while(old_cumulative_brightness > histogramm_map[j]) j++; if(j > 255) j = 255; brightness_map[i] = j; }