[TASK] Move intensity calculation to seperate method, increase precision using qRound.
This commit is contained in:
		
							parent
							
								
									c2421582b5
								
							
						
					
					
						commit
						3fe80df7f9
					
				| @ -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; | ||||
|     } | ||||
|  | ||||
| @ -41,6 +41,7 @@ | ||||
| #ifndef IMAGEVIEWER_H | ||||
| #define IMAGEVIEWER_H | ||||
| 
 | ||||
| #include <QtGlobal> | ||||
| #include <QMainWindow> | ||||
| #include <QPrinter> | ||||
| #include <QtGui> | ||||
| @ -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(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user