[TASK] Add an imagelabel, create and display the histogramm.
This commit is contained in:
parent
2d7b437758
commit
6001e3d6ce
|
@ -160,27 +160,24 @@ void ImageViewer::analyzeImage() {
|
|||
renewLogging();
|
||||
for(int x=0; x<image->width(); x++) {
|
||||
for(int y=0; y<image->height(); 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; y<k_max; y++) {
|
||||
histogramm->setPixel(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);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <QSlider>
|
||||
#include <QColor>
|
||||
|
||||
#include <cmath>
|
||||
#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();
|
||||
|
|
Loading…
Reference in New Issue