[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
1 changed files with 6 additions and 9 deletions

View File

@ -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;
}