大家好我正在编写一个读取ppm图像并打印图像平均亮度的c ++代码。我创建了一个Color类,其中包含图像的像素为红色,绿色,蓝色三元组。我有一个Image类,表示图像的通用数据容器(宽度,高度和保存图像数据的指针)。我还有读取图像文件并创建图像对象的readppm方法。我的问题是我怎么能找到我主类中图像的平均亮度。 这是主要的应用程序:
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);
}
}
}
感谢任何帮助。