diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index 0e7b023..94bda10 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -73,6 +73,10 @@ void ImageViewer::initializeImage() { analyzeImage(); } +int ImageViewer::calcIntensity(int r, int g, int b) { + return (int) qRound(0.299*r + 0.587*g + 0.114*b); +} + /** * In case it is needed, convert the loaded image into grayscale. * @brief ImageViewer::convertToMonochrome @@ -86,7 +90,7 @@ void ImageViewer::convertToMonochrome() { int r,g,b; QColor color = QColor::fromRgb(image->pixel(x, y)); color.getRgb(&r,&g,&b); - int intensity = (int)(0.299*r+0.587*g+0.114*b); + int intensity = calcIntensity(r, g, b); color = QColor::fromRgb(intensity, intensity, intensity); image->setPixel(x, y, color.rgba()); original_image->setPixel(x, y, color.rgba()); @@ -206,7 +210,7 @@ void ImageViewer::analyzeImage() { int r,g,b; QColor color = QColor::fromRgb(image->pixel(x, y)); color.getRgb(&r,&g,&b); - int intensity = (int)(0.299*r+0.587*g+0.114*b); + int intensity = calcIntensity(r, g, b); grayscale_absolute_histogramm[intensity] += 1; } } @@ -250,7 +254,7 @@ int ImageViewer::getIntensityVariance() { QColor color = QColor::fromRgb(image->pixel(x, y)); int r,g,b; color.getRgb(&r,&g,&b); - int intensity = (int)(0.299*r+0.587*g+0.114*b); + int intensity = calcIntensity(r, g, b); int diff = std::abs(intensity - average_intensity); sumDifference += diff; } diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index ce7b639..1cf60e9 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -41,6 +41,7 @@ #ifndef IMAGEVIEWER_H #define IMAGEVIEWER_H +#include #include #include #include @@ -132,6 +133,7 @@ class ImageViewer : public QMainWindow { private: // Custom methods + int calcIntensity(int r, int g, int b); void drawRainbowCross(int h); int getAverageIntensity(); int getIntensityVariance();