[TASK] Almost finish piecebased histogramm adaption.

This commit is contained in:
Jan Philipp Timme 2015-11-20 13:31:27 +01:00
parent 0fa09a775b
commit c0ed071190
3 changed files with 68 additions and 1 deletions

View File

@ -363,6 +363,59 @@ void ImageViewer::linearHistogrammAdaption(void) {
renewLogging();
}
/**
* Do a piece based linear histogramm adaption using a reference image.
*
* @brief Imageviewer::pieceLinearHistogrammAdaption
*/
void ImageViewer::pieceLinearHistogrammAdaption() {
logFile << "Doing linear histogramm adaption ..." << std::endl;
renewLogging();
if(histogramm_reference == NULL) {
logFile << "No reference image loaded! Aborting." << std::endl;
renewLogging();
return;
} else {
// Create an intensity map
int histogramm_map[256];
for(int i=0; i<256; i++) histogramm_map[i] = -1;
int source_cursor = 0;
double used_space = 0.0;
double* source_histogramm = working_copy->getRelativeIntensityHistogramm();
double* target_cummulative_histogramm = histogramm_reference->getRelativeCumulativeIntensityHistogramm();
for(int i=0; i<256; i++) {
double free_total_space = target_cummulative_histogramm[i];
while(source_histogramm[source_cursor] <= (free_total_space - used_space)) {
histogramm_map[source_cursor] = i;
used_space += source_histogramm[source_cursor];
source_cursor++;
}
}
for(int i=0; i<256; i++) {
logFile << i << ": " << histogramm_map[i] << std::endl;
}
renewLogging();
// Apply the map for each pixel.
int h, s, l;
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 = histogramm_map[l];
color.setHsl(h, s, l);
working_copy->getImage()->setPixel(x, y, color.rgb());
}
}
// Done.
}
logFile << "done." << std::endl;
renewLogging();
updateImageDisplay();
}
/****************************************************************************************
*
@ -512,6 +565,9 @@ void ImageViewer::generateControlPanels() {
linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (basic)");
QObject::connect(linear_histogramm_adaption, SIGNAL(clicked()), this, SLOT(linearHistogrammAdaption()));
piece_linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (pieces)");
QObject::connect(piece_linear_histogramm_adaption, SIGNAL(clicked()), this, SLOT(pieceLinearHistogrammAdaption()));
task_tab3->addWidget(new QLabel("Reference image"));
task_tab3->addWidget(reference_histogramm_cumulative_label);
task_tab3->addWidget(new QLabel("Original image"));
@ -519,6 +575,7 @@ void ImageViewer::generateControlPanels() {
task_tab3->addWidget(new QLabel("Working copy"));
task_tab3->addWidget(histogramm_cumulative_label);
task_tab3->addWidget(linear_histogramm_adaption);
task_tab3->addWidget(piece_linear_histogramm_adaption);
tabWidget->addTab(task_tab_widget3, "Task #3");

View File

@ -110,6 +110,7 @@ class ImageViewer : public QMainWindow {
QLabel* histogramm_cumulative_label;
QPushButton* linear_histogramm_adaption;
QPushButton* piece_linear_histogramm_adaption;
// "My" space for storing data/results
LazyImage* original;
@ -129,6 +130,7 @@ class ImageViewer : public QMainWindow {
void saveToOriginal();
void robustAutomaticContrastAdaption(int c_param);
void linearHistogrammAdaption();
void pieceLinearHistogrammAdaption();
void open();
void openReference();

View File

@ -16,6 +16,7 @@ class LazyImage {
QImage* histogramm_normal_image;
QImage* histogramm_cumulative_image;
double histogramm_relative_intensity[256];
double histogramm_relative_cumulative_intensity[256];
int histogramm_absolute_intensity[256];
int histogramm_absolute_cumulative_intensity[256];
int intensity_average;
@ -42,10 +43,13 @@ class LazyImage {
// Calculate relative histogramm and absolute cumulative histogramm
int pixels = this->img->width()*this->img->height();
int sum = 0;
double relative_sum = 0.0;
for(int i=0; i<256; i++) {
histogramm_relative_intensity[i] = (((double) histogramm_absolute_intensity[i])/((double) pixels));
sum += histogramm_absolute_intensity[i];
relative_sum += histogramm_relative_intensity[i];
histogramm_absolute_cumulative_intensity[i] = sum;
histogramm_relative_cumulative_intensity[i] = relative_sum;
}
};
@ -181,6 +185,10 @@ class LazyImage {
return this->histogramm_relative_intensity;
};
double* getRelativeCumulativeIntensityHistogramm(void) {
return this->histogramm_relative_cumulative_intensity;
};
void convertToMonochrome(void) {
for(int x=0; x<this->img->width(); x++) {
for(int y=0; y<this->img->height(); y++) {