[TASK] Add cumulative histogramms.
This commit is contained in:
parent
bc5bec953f
commit
42bf3fb44e
|
@ -197,8 +197,10 @@ void ImageViewer::analyzeImage() {
|
|||
original_stats->setText(result);
|
||||
result = QString("Intensity: Average: %1, Variance: %2").arg(working_copy->getIntensityAverage()).arg(working_copy->getIntensityVariance());
|
||||
stats->setText(result);
|
||||
histogramm_label->setPixmap(QPixmap::fromImage(*(working_copy->getHistogrammImage())));
|
||||
original_histogramm_label->setPixmap(QPixmap::fromImage(*(original->getHistogrammImage())));
|
||||
histogramm_label->setPixmap(QPixmap::fromImage(*(working_copy->getHistogrammNormalImage())));
|
||||
original_histogramm_label->setPixmap(QPixmap::fromImage(*(original->getHistogrammNormalImage())));
|
||||
histogramm_cumulative_label->setPixmap(QPixmap::fromImage(*(working_copy->getHistogrammCumulativeImage())));
|
||||
original_histogramm_cumulative_label->setPixmap(QPixmap::fromImage(*(original->getHistogrammCumulativeImage())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +253,7 @@ void ImageViewer::adjustContrast(int c) {
|
|||
renewLogging();
|
||||
}
|
||||
|
||||
/** copy
|
||||
/**
|
||||
* Using the percentile given by the slider, do a robust automatic contrast adaption.
|
||||
*
|
||||
* @brief ImageViewer::robustAutomaticContrastAdaption
|
||||
|
@ -431,6 +433,21 @@ void ImageViewer::generateControlPanels() {
|
|||
task_tab3 = new QVBoxLayout();
|
||||
task_tab_widget3->setLayout(task_tab3);
|
||||
|
||||
original_histogramm_cumulative_label = new QLabel();
|
||||
original_histogramm_cumulative_label->setBackgroundRole(QPalette::Base);
|
||||
original_histogramm_cumulative_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
original_histogramm_cumulative_label->setScaledContents(false);
|
||||
|
||||
histogramm_cumulative_label = new QLabel();
|
||||
histogramm_cumulative_label->setBackgroundRole(QPalette::Base);
|
||||
histogramm_cumulative_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
histogramm_cumulative_label->setScaledContents(false);
|
||||
|
||||
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);
|
||||
|
||||
tabWidget->addTab(task_tab_widget3, "Task #3");
|
||||
|
||||
//Show it
|
||||
|
|
|
@ -102,6 +102,9 @@ class ImageViewer : public QMainWindow {
|
|||
QWidget* task_tab_widget3;
|
||||
QVBoxLayout* task_tab3;
|
||||
|
||||
QLabel* original_histogramm_cumulative_label;
|
||||
QLabel* histogramm_cumulative_label;
|
||||
|
||||
// "My" space for storing data/results
|
||||
LazyImage* original;
|
||||
LazyImage* working_copy;
|
||||
|
|
|
@ -13,7 +13,8 @@ class LazyImage {
|
|||
|
||||
private:
|
||||
QImage* img; //Not managed by us, just used.
|
||||
QImage* histogramm_image;
|
||||
QImage* histogramm_normal_image;
|
||||
QImage* histogramm_cumulative_image;
|
||||
double histogramm_relative_intensity[256];
|
||||
int histogramm_absolute_intensity[256];
|
||||
int intensity_average;
|
||||
|
@ -64,24 +65,41 @@ class LazyImage {
|
|||
this->intensity_variance = (int) qRound(sum_difference/(this->img->width()*this->img->height()));
|
||||
};
|
||||
|
||||
void generateHistogrammImage(void) {
|
||||
if(this->histogramm_image != NULL) {
|
||||
delete this->histogramm_image;
|
||||
this->histogramm_image = NULL;
|
||||
void generateNormalHistogrammImage(void) {
|
||||
if(this->histogramm_normal_image != NULL) {
|
||||
delete this->histogramm_normal_image;
|
||||
this->histogramm_normal_image = NULL;
|
||||
}
|
||||
//Find biggest value in histogramm data
|
||||
double max = 0;
|
||||
for(int i=0; i<256; i++) {
|
||||
if(histogramm_relative_intensity[i] > max) max = histogramm_relative_intensity[i];
|
||||
}
|
||||
|
||||
this->histogramm_image = new QImage(256, 100, QImage::Format_RGB32);
|
||||
this->histogramm_image->fill(QColor::fromRgb(200,200,200));
|
||||
}
|
||||
this->histogramm_normal_image = new QImage(256, 100, QImage::Format_RGB32);
|
||||
this->histogramm_normal_image->fill(QColor::fromRgb(200,200,200));
|
||||
int black = QColor::fromRgb(0,0,0).rgb();
|
||||
for(int x=0; x<256; x++) {
|
||||
int k_max = (int) qRound((100*histogramm_relative_intensity[x])/max);
|
||||
for(int y=0; y<k_max; y++) {
|
||||
this->histogramm_image->setPixel(x, (100-y)-1, black);
|
||||
this->histogramm_normal_image->setPixel(x, (100-y)-1, black);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void generateCumulativeHistogrammImage(void) {
|
||||
if(this->histogramm_cumulative_image != NULL) {
|
||||
delete this->histogramm_cumulative_image;
|
||||
this->histogramm_cumulative_image = NULL;
|
||||
}
|
||||
this->histogramm_cumulative_image = new QImage(256, 100, QImage::Format_RGB32);
|
||||
this->histogramm_cumulative_image->fill(QColor::fromRgb(200,200,200));
|
||||
int black = QColor::fromRgb(0,0,0).rgb();
|
||||
double total = 0.0;
|
||||
for(int x=0; x<256; x++) {
|
||||
total += histogramm_relative_intensity[x];
|
||||
int k_max = (int) qRound(100*total);
|
||||
for(int y=0; y<k_max; y++) {
|
||||
this->histogramm_cumulative_image->setPixel(x, (100-y)-1, black);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -89,7 +107,8 @@ class LazyImage {
|
|||
|
||||
public:
|
||||
LazyImage(QImage* img) {
|
||||
this->histogramm_image = NULL;
|
||||
this->histogramm_normal_image = NULL;
|
||||
this->histogramm_cumulative_image = NULL;
|
||||
this->setImage(img);
|
||||
};
|
||||
|
||||
|
@ -114,11 +133,16 @@ class LazyImage {
|
|||
this->gatherHistogrammData();
|
||||
this->calcIntensityAverage();
|
||||
this->calcIntensityVariance();
|
||||
this->generateHistogrammImage();
|
||||
this->generateNormalHistogrammImage();
|
||||
this->generateCumulativeHistogrammImage();
|
||||
};
|
||||
|
||||
QImage* getHistogrammImage(void) {
|
||||
return this->histogramm_image;
|
||||
QImage* getHistogrammNormalImage(void) {
|
||||
return this->histogramm_normal_image;
|
||||
};
|
||||
|
||||
QImage* getHistogrammCumulativeImage(void) {
|
||||
return this->histogramm_cumulative_image;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue