[TASK] Not quite sure, but partial linear histogramm adaption seems to be done.

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

View File

@ -375,17 +375,19 @@ void ImageViewer::partialLinearHistogrammAdaption() {
double* reference_histogramm = histogramm_reference->getRelativeCumulativeIntensityHistogramm();
// Split [0,255] into n parts (slider)
// This produces a list of brightness indexes to interpolate in between.
int number_parts = partial_adaption_pieces_slider->value();
int* parts = (int*) malloc(number_parts*sizeof(int));
for(int i=0; i<number_parts; i++) {
int* parts = (int*) malloc((number_parts+1)*sizeof(int));
for(int i=0; i<=number_parts; i++) {
parts[i] = qRound((255.0/number_parts)*i);
logFile << "I: " << i << ", intensity: " << parts[i] << std::endl;
}
// Create
// TODO TODO TODO
// 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 :/ )
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];
if(current_n == 0) continue; // First part is always at zero!
int last_n = parts[i-1];
@ -393,7 +395,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];
// Fill in the blanks
// Calculate the mapping values
for(int j=last_n; j<=current_n; j++) {
int delta_n = j - last_n;
histogramm_map[j] = (offset + delta_n*m);
@ -401,20 +403,39 @@ void ImageViewer::partialLinearHistogrammAdaption() {
}
}
// Apply the histogramm map (see succeeding Histogramm Adaption)
/*
// Build up the brightness map to apply on the image
// (basically reversing and applying the histogramm map)
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;
for(j=0; j<256; j++) {
if(old_brightness_occurrence < histogramm_map[j]) break;
}
if(j > 255) j = 255;
brightness_map[i] = j;
}
for(int i=0; i<256; i++) {
logFile << i << " -> " << brightness_map[i] << std::endl;
}
renewLogging();
// Apply the brightness map
int h, s, l;
int pixels = working_copy->getImage()->width() * working_copy->getImage()->height();
for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) {
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
color.getHsl(&h, &s, &l);
l = qRound(histogramm_map[l] * (255/pixels));
l = brightness_map[l];
color.setHsl(h, s, l);
working_copy->getImage()->setPixel(x, y, color.rgb());
}
}*/
}
// Done.
free(brightness_map);
free(histogramm_map);
free(parts);
logFile << "done." << std::endl;
@ -788,7 +809,7 @@ void ImageViewer::generateControlPanels() {
partial_adaption_pieces_slider = new QSlider(Qt::Horizontal);
partial_adaption_pieces_slider->setMinimum(2);
partial_adaption_pieces_slider->setMaximum(10);
partial_adaption_pieces_slider->setMaximum(20);
partial_adaption_pieces_slider->setValue(5);
//QObject::connect(partial_adaption_pieces_slider, SIGNAL(valueChanged(int)), this, SLOT(robustAutomaticContrastAdaption(int)));