From 6ddb7981771b8783fad32bfd56f0414200fce97f Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 11 Dec 2015 14:47:16 +0100 Subject: [PATCH] [TASK] Fix contrast calculation. --- lazy_image.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lazy_image.cpp b/lazy_image.cpp index 432c163..08adc57 100644 --- a/lazy_image.cpp +++ b/lazy_image.cpp @@ -65,21 +65,16 @@ class LazyImage { for(int i=0; i<256;i++) { sum += (i*histogramm_relative_intensity[i]); } - this->intensity_average = (int) qRound(sum); + this->intensity_average = qRound(sum); }; void calcIntensityVariance(void) { int intensity_average = this->intensity_average; - int sum_difference = 0; - for(int x=0; ximg->width(); x++) { - for(int y=0; yimg->height(); y++) { - QColor color = QColor::fromRgb(this->img->pixel(x, y)); - int r,g,b; - color.getRgb(&r,&g,&b); - sum_difference += std::abs(this->calcIntensity(r, g, b) - intensity_average);; - } + double sum = 0; + for(int i=0; i<256; i++) { + sum += histogramm_relative_intensity[i] * pow((i - intensity_average),2); } - this->intensity_variance = (int) qRound(sum_difference/(this->img->width()*this->img->height())); + this->intensity_variance = qRound(sum); }; void generateNormalHistogrammImage(void) {