diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index c3a9038..06e9d40 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -160,27 +160,24 @@ void ImageViewer::analyzeImage() { renewLogging(); for(int x=0; xwidth(); x++) { for(int y=0; yheight(); y++) { - logFile << "(" << x << "," << y << "): "; int r,g,b; QColor color = QColor::fromRgb(image->pixel(x, y)); color.getRgb(&r,&g,&b); - logFile << "(" << r << "," << g << "," << b << ")"; int intensity = (int)(0.299*r+0.587*g+0.114*b); - logFile << "(" << intensity << ")"; grayscale_absolute_histogramm[intensity] += 1; - logFile << std::endl; } } int pixels = image->width()*image->height(); for(int i=0; i<256; i++) { - grayscale_relative_histogramm[i] = ((1.0*grayscale_absolute_histogramm[i])/(1.0*pixels)); + grayscale_relative_histogramm[i] = (((double) grayscale_absolute_histogramm[i])/((double) pixels)); } logFile << "done" << std::endl; logFile << "Average intensity: " << getAverageIntensity() << std::endl; logFile << "Intensity variance: " << getIntensityVariance() << std::endl; renewLogging(); + updateHistogramm(); } } @@ -220,14 +217,29 @@ int ImageViewer::getIntensityVariance() { * Builds up the image for the histogramm. * @brief ImageViewer::updateHistogramm */ -void updateHistogramm() { - histogramm = new QImage(256, 100); - histogramm.fill(QColor::fromRgb(255,255,255)); +void ImageViewer::updateHistogramm() { + if(histogramm != NULL) { + delete histogramm; + histogramm = NULL; + } + //Find biggest value in histogramm data + double max = 0; for(int i=0; i<256; i++) { - + if(grayscale_relative_histogramm[i] > max) max = grayscale_relative_histogramm[i]; + } + + histogramm = new QImage(256, 100, QImage::Format_RGB32); + histogramm->fill(QColor::fromRgb(150,150,150)); + int black = QColor::fromRgb(0,0,0).rgba(); + for(int x=0; x<256; x++) { + int k_max = (int)((100*grayscale_relative_histogramm[x])/max); + for(int y=0; ysetPixel(x, (100-y)-1, black); + } } logFile << "Histogramm done." << std::endl; renewLogging(); + histogrammLabel->setPixmap(QPixmap::fromImage(*histogramm)); } /**************************************************************************************** @@ -281,6 +293,11 @@ void ImageViewer::generateControlPanels() { task_tab2_button1->setText("Analyze image"); QObject::connect(task_tab2_button1, SIGNAL(clicked()), this, SLOT (analyzeImage())); + histogrammLabel = new QLabel(); + histogrammLabel->setBackgroundRole(QPalette::Base); + histogrammLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + histogrammLabel->setScaledContents(false); + QLabel* task_tab2_stats = new QLabel(); task_tab_widget2 = new QWidget(); @@ -289,6 +306,7 @@ void ImageViewer::generateControlPanels() { task_tab2->addWidget(task_tab2_button1); task_tab2->addWidget(task_tab2_stats); + task_tab2->addWidget(histogrammLabel); tabWidget->addTab(task_tab_widget2,"Task #2"); tabWidget->show(); @@ -397,7 +415,7 @@ void ImageViewer::open() { QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName)); return; } - + scaleFactor = 1.0; updateImageDisplay(); printAct->setEnabled(true); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index c8efc64..a48f113 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -49,6 +49,7 @@ #include #include +#include #include "fstream" class QAction; @@ -83,6 +84,7 @@ class ImageViewer : public QMainWindow { QPushButton* task_tab2_button1; QLabel* task_tab2_stats; + QLabel* histogrammLabel; // "My" space for storing data/results int grayscale_absolute_histogramm[256]; @@ -96,7 +98,8 @@ class ImageViewer : public QMainWindow { void drawDiagonalCross(); void acidTrippin(); void analyzeImage(); - + void updateHistogramm(); + void open(); void print(); void zoomIn();