[TASK] Not really done, but this seems logically correct.

This commit is contained in:
Jan Philipp Timme 2015-12-04 14:18:14 +01:00
parent 839308fe33
commit 662f990877

View File

@ -384,8 +384,7 @@ void ImageViewer::partialLinearHistogrammAdaption() {
} }
// Create histogramm map // Create histogramm map
// This will point every new brightness index to the old double value // This represents the new cumulative histogramm built of linear parts
// from the reference histogramm. (array with double index, but the other way around :/ )
double* histogramm_map = (double*) malloc(256*sizeof(double)); double* histogramm_map = (double*) malloc(256*sizeof(double));
for(int i=0; i<=number_parts; i++) { for(int i=0; i<=number_parts; i++) {
int current_n = 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 delta_i = reference_histogramm[current_n] - reference_histogramm[last_n];
double m = delta_i / delta_n; double m = delta_i / delta_n;
double offset = histogramm_map[last_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++) { for(int j=last_n; j<=current_n; j++) {
int delta_n = j - last_n; int delta_n = j - last_n;
histogramm_map[j] = (offset + delta_n*m); histogramm_map[j] = (offset + delta_n*m);
@ -404,14 +403,12 @@ void ImageViewer::partialLinearHistogrammAdaption() {
} }
// Build up the brightness map to apply on the image // 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* brightness_map = (int*) malloc(256*sizeof(int));
for(int i=0; i<256; i++) {
double old_brightness_occurrence = reference_histogramm[i];
int j=0; int j=0;
for(j=0; j<256; j++) { for(int i=0; i<256; i++) {
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; if(j > 255) j = 255;
brightness_map[i] = j; brightness_map[i] = j;
} }