0

Hello everybody I am writing a c++ code that reads a ppm image and print the average brightness of the image.I have created a Color class that contains the pixels of the image as a red , green, blue triplet. I have an Image class that represents a generic data container for an image(width,height and a pointer that hold the image data).I also have readppm method that reads the image file and create an image object.My question is how can I find the average brightness of the image in my main class. Here is the main app:

using namespace std;
#include <iostream>
#include "ppm_format.h"
#include "Image.h"
#include "Color.h"
using namespace imaging;

int main() {
char fname[50];
cout << "Please enter the file name: ";
cin >> fname;
Image *img = ReadPPM(fname);
cout <<"Image Width :" << img->getWidth() << endl;
cout << "Image Height :" << img->getHeight() << endl;

int sum_r = 0;
int sum_g = 0;
int sum_b = 0;

for (int i = 0; i < img->getWidth(); i++) {
    for (j = 0; j < img->getHeight(); j++) {
        Color pix = img->getPixel(i,j);

    }
}
}

Any help is appreciated.

  • 1. What main class? You haven't defined any classes here. 2. What have you tried doing? Do you know how to calculate an average? (if yes, then why isn't that happening in your code?) – UnholySheep Nov 25 '16 at 13:23
  • I dont know how –  Nov 25 '16 at 13:24
  • 2
    Possible duplicate of : http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color – Fefux Nov 25 '16 at 13:25
  • 1
    The trivial solution is to sum the values of all red, green, and blue pixels and divide the results by 3 * height * width. For better results, use the luminance formula found in the link provided by Fefux – Sven Nilsson Nov 25 '16 at 13:26

0 Answers0