[TASK] Almost finish piecebased histogramm adaption.
This commit is contained in:
parent
0fa09a775b
commit
c0ed071190
|
@ -363,6 +363,59 @@ void ImageViewer::linearHistogrammAdaption(void) {
|
||||||
renewLogging();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -511,7 +564,10 @@ void ImageViewer::generateControlPanels() {
|
||||||
|
|
||||||
linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (basic)");
|
linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (basic)");
|
||||||
QObject::connect(linear_histogramm_adaption, SIGNAL(clicked()), this, SLOT(linearHistogrammAdaption()));
|
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(new QLabel("Reference image"));
|
||||||
task_tab3->addWidget(reference_histogramm_cumulative_label);
|
task_tab3->addWidget(reference_histogramm_cumulative_label);
|
||||||
task_tab3->addWidget(new QLabel("Original image"));
|
task_tab3->addWidget(new QLabel("Original image"));
|
||||||
|
@ -519,6 +575,7 @@ void ImageViewer::generateControlPanels() {
|
||||||
task_tab3->addWidget(new QLabel("Working copy"));
|
task_tab3->addWidget(new QLabel("Working copy"));
|
||||||
task_tab3->addWidget(histogramm_cumulative_label);
|
task_tab3->addWidget(histogramm_cumulative_label);
|
||||||
task_tab3->addWidget(linear_histogramm_adaption);
|
task_tab3->addWidget(linear_histogramm_adaption);
|
||||||
|
task_tab3->addWidget(piece_linear_histogramm_adaption);
|
||||||
|
|
||||||
tabWidget->addTab(task_tab_widget3, "Task #3");
|
tabWidget->addTab(task_tab_widget3, "Task #3");
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ class ImageViewer : public QMainWindow {
|
||||||
QLabel* histogramm_cumulative_label;
|
QLabel* histogramm_cumulative_label;
|
||||||
|
|
||||||
QPushButton* linear_histogramm_adaption;
|
QPushButton* linear_histogramm_adaption;
|
||||||
|
QPushButton* piece_linear_histogramm_adaption;
|
||||||
|
|
||||||
// "My" space for storing data/results
|
// "My" space for storing data/results
|
||||||
LazyImage* original;
|
LazyImage* original;
|
||||||
|
@ -129,6 +130,7 @@ class ImageViewer : public QMainWindow {
|
||||||
void saveToOriginal();
|
void saveToOriginal();
|
||||||
void robustAutomaticContrastAdaption(int c_param);
|
void robustAutomaticContrastAdaption(int c_param);
|
||||||
void linearHistogrammAdaption();
|
void linearHistogrammAdaption();
|
||||||
|
void pieceLinearHistogrammAdaption();
|
||||||
|
|
||||||
void open();
|
void open();
|
||||||
void openReference();
|
void openReference();
|
||||||
|
|
|
@ -16,6 +16,7 @@ class LazyImage {
|
||||||
QImage* histogramm_normal_image;
|
QImage* histogramm_normal_image;
|
||||||
QImage* histogramm_cumulative_image;
|
QImage* histogramm_cumulative_image;
|
||||||
double histogramm_relative_intensity[256];
|
double histogramm_relative_intensity[256];
|
||||||
|
double histogramm_relative_cumulative_intensity[256];
|
||||||
int histogramm_absolute_intensity[256];
|
int histogramm_absolute_intensity[256];
|
||||||
int histogramm_absolute_cumulative_intensity[256];
|
int histogramm_absolute_cumulative_intensity[256];
|
||||||
int intensity_average;
|
int intensity_average;
|
||||||
|
@ -42,10 +43,13 @@ class LazyImage {
|
||||||
// Calculate relative histogramm and absolute cumulative histogramm
|
// Calculate relative histogramm and absolute cumulative histogramm
|
||||||
int pixels = this->img->width()*this->img->height();
|
int pixels = this->img->width()*this->img->height();
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
double relative_sum = 0.0;
|
||||||
for(int i=0; i<256; i++) {
|
for(int i=0; i<256; i++) {
|
||||||
histogramm_relative_intensity[i] = (((double) histogramm_absolute_intensity[i])/((double) pixels));
|
histogramm_relative_intensity[i] = (((double) histogramm_absolute_intensity[i])/((double) pixels));
|
||||||
sum += histogramm_absolute_intensity[i];
|
sum += histogramm_absolute_intensity[i];
|
||||||
|
relative_sum += histogramm_relative_intensity[i];
|
||||||
histogramm_absolute_cumulative_intensity[i] = sum;
|
histogramm_absolute_cumulative_intensity[i] = sum;
|
||||||
|
histogramm_relative_cumulative_intensity[i] = relative_sum;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,6 +185,10 @@ class LazyImage {
|
||||||
return this->histogramm_relative_intensity;
|
return this->histogramm_relative_intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
double* getRelativeCumulativeIntensityHistogramm(void) {
|
||||||
|
return this->histogramm_relative_cumulative_intensity;
|
||||||
|
};
|
||||||
|
|
||||||
void convertToMonochrome(void) {
|
void convertToMonochrome(void) {
|
||||||
for(int x=0; x<this->img->width(); x++) {
|
for(int x=0; x<this->img->width(); x++) {
|
||||||
for(int y=0; y<this->img->height(); y++) {
|
for(int y=0; y<this->img->height(); y++) {
|
||||||
|
|
Loading…
Reference in New Issue