[TASK] Implement linear histogramm adaption
This commit is contained in:
parent
42bf3fb44e
commit
1109fda972
@ -316,6 +316,33 @@ void ImageViewer::robustAutomaticContrastAdaption(int c_param) {
|
||||
renewLogging();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a very basic, linear histogramm adaption.
|
||||
*
|
||||
* @brief ImageViewer::linearHistogrammAdaption
|
||||
*/
|
||||
void ImageViewer::linearHistogrammAdaption(void) {
|
||||
logFile << "Doing linear histogramm adaption ..." << std::endl;
|
||||
renewLogging();
|
||||
int h, s, l;
|
||||
int* ach = original->getAbsoluteCumulativeIntensityHistogramm();
|
||||
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 = (int) qFloor(ach[l] * (255.0/pixels));
|
||||
|
||||
color.setHsl(h, s, l);
|
||||
working_copy->getImage()->setPixel(x, y, color.rgb());
|
||||
}
|
||||
}
|
||||
updateImageDisplay();
|
||||
logFile << "done." << std::endl;
|
||||
renewLogging();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
@ -408,8 +435,7 @@ void ImageViewer::generateControlPanels() {
|
||||
contrast_percentile_slider = new QSlider(Qt::Horizontal);
|
||||
contrast_percentile_slider->setMinimum(0);
|
||||
contrast_percentile_slider->setMaximum(100);
|
||||
contrast_percentile_slider->setValue(10);
|
||||
|
||||
contrast_percentile_slider->setValue(10);
|
||||
QObject::connect(contrast_percentile_slider, SIGNAL(valueChanged(int)), this, SLOT(robustAutomaticContrastAdaption(int)));
|
||||
|
||||
task_tab2->addWidget(new QLabel("Original image"));
|
||||
@ -443,10 +469,14 @@ void ImageViewer::generateControlPanels() {
|
||||
histogramm_cumulative_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
histogramm_cumulative_label->setScaledContents(false);
|
||||
|
||||
linear_histogramm_adaption = new QPushButton("Do linear histogramm adaption (basic)");
|
||||
QObject::connect(linear_histogramm_adaption, SIGNAL(clicked()), this, SLOT(linearHistogrammAdaption()));
|
||||
|
||||
task_tab3->addWidget(new QLabel("Original image"));
|
||||
task_tab3->addWidget(original_histogramm_cumulative_label);
|
||||
task_tab3->addWidget(new QLabel("Working copy"));
|
||||
task_tab3->addWidget(histogramm_cumulative_label);
|
||||
task_tab3->addWidget(linear_histogramm_adaption);
|
||||
|
||||
tabWidget->addTab(task_tab_widget3, "Task #3");
|
||||
|
||||
|
@ -105,6 +105,8 @@ class ImageViewer : public QMainWindow {
|
||||
QLabel* original_histogramm_cumulative_label;
|
||||
QLabel* histogramm_cumulative_label;
|
||||
|
||||
QPushButton* linear_histogramm_adaption;
|
||||
|
||||
// "My" space for storing data/results
|
||||
LazyImage* original;
|
||||
LazyImage* working_copy;
|
||||
@ -120,6 +122,7 @@ class ImageViewer : public QMainWindow {
|
||||
void convertToMonochrome();
|
||||
void resetWorkingCopy();
|
||||
void robustAutomaticContrastAdaption(int c_param);
|
||||
void linearHistogrammAdaption();
|
||||
|
||||
void open();
|
||||
void print();
|
||||
|
@ -17,6 +17,7 @@ class LazyImage {
|
||||
QImage* histogramm_cumulative_image;
|
||||
double histogramm_relative_intensity[256];
|
||||
int histogramm_absolute_intensity[256];
|
||||
int histogramm_absolute_cumulative_intensity[256];
|
||||
int intensity_average;
|
||||
int intensity_variance;
|
||||
|
||||
@ -25,6 +26,7 @@ class LazyImage {
|
||||
for(int i=0; i<256; i++) {
|
||||
histogramm_relative_intensity[i] = 0;
|
||||
histogramm_absolute_intensity[i] = 0;
|
||||
histogramm_absolute_cumulative_intensity[i] = 0;
|
||||
}
|
||||
// Count all the brightness values
|
||||
for(int x=0; x<this->img->width(); x++) {
|
||||
@ -35,11 +37,15 @@ class LazyImage {
|
||||
int intensity = this->calcIntensity(r, g, b);
|
||||
histogramm_absolute_intensity[intensity] += 1;
|
||||
}
|
||||
}
|
||||
// Calculate relative histogramm
|
||||
}
|
||||
|
||||
// Calculate relative histogramm and absolute cumulative histogramm
|
||||
int pixels = this->img->width()*this->img->height();
|
||||
int sum = 0;
|
||||
for(int i=0; i<256; i++) {
|
||||
histogramm_relative_intensity[i] = (((double) histogramm_absolute_intensity[i])/((double) pixels));
|
||||
sum += histogramm_absolute_intensity[i];
|
||||
histogramm_absolute_cumulative_intensity[i] = sum;
|
||||
}
|
||||
};
|
||||
|
||||
@ -166,7 +172,11 @@ class LazyImage {
|
||||
int* getAbsoluteIntensityHistogramm(void) {
|
||||
return this->histogramm_absolute_intensity;
|
||||
};
|
||||
|
||||
|
||||
int* getAbsoluteCumulativeIntensityHistogramm(void) {
|
||||
return this->histogramm_absolute_cumulative_intensity;
|
||||
};
|
||||
|
||||
double* getRelativeIntensityHistogramm(void) {
|
||||
return this->histogramm_relative_intensity;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user