juexxs
asked on
compute mean and standard deviation of RGB color
Hello..., I really need your help..URGENT..and please reply as soon as
possible. I was given a few sample of images in BMP format (device-
independent-bitmap(DIB). Can you give me a few sample of the source code
on how to compute the mean and the standard deviation on the RGB color
for each sample to take the average color to get the standard color of the
image( for example I took 10 sample of images of pepper berries). Thanx.
possible. I was given a few sample of images in BMP format (device-
independent-bitmap(DIB). Can you give me a few sample of the source code
on how to compute the mean and the standard deviation on the RGB color
for each sample to take the average color to get the standard color of the
image( for example I took 10 sample of images of pepper berries). Thanx.
Sounds like homework...
I'm not sure. That sounds too weird to be even homework.
There is a lot involved in this process. Can you tell us what you problem areas are? also if it is homework, we will still be happy to HELP you, but we won't do it for you. For (100 points on a question of this size, no one is likely to do it for you in any case).
There is a lot involved in this process. Can you tell us what you problem areas are? also if it is homework, we will still be happy to HELP you, but we won't do it for you. For (100 points on a question of this size, no one is likely to do it for you in any case).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is some code using OpenGL functions to read in the bitmap from a file and compute the average colour
#include <glu.h>
#include <GLAUX.H>
COLORREF AverageColor (LPCTSTR filename) {
AUX_RGBImageRec *pImage;
glPixelStorei(GL_PACK_ALIG NMENT, 1);
glPixelStorei(GL_UNPACK_AL IGNMENT, 1);
pImage = ::auxDIBImageLoad(filename );
int sum[3] = {0,0,0};
int ave[3];
int n = pImage->sizeX*pImage->size Y;
for (int i = 0; i < n*3; i+=3) {
sum[0] += pImage->data[i+0];
sum[1] += pImage->data[i+1];
sum[2] += pImage->data[i+2];
}
ave[0] = unsigned char (sum[0]/n);
ave[1] = unsigned char (sum[1]/n);
ave[2] = unsigned char (sum[2]/n);
return RGB(ave[0],ave[1],ave[2]);
}
You can expand this to do std dev etc.
#include <glu.h>
#include <GLAUX.H>
COLORREF AverageColor (LPCTSTR filename) {
AUX_RGBImageRec *pImage;
glPixelStorei(GL_PACK_ALIG
glPixelStorei(GL_UNPACK_AL
pImage = ::auxDIBImageLoad(filename
int sum[3] = {0,0,0};
int ave[3];
int n = pImage->sizeX*pImage->size
for (int i = 0; i < n*3; i+=3) {
sum[0] += pImage->data[i+0];
sum[1] += pImage->data[i+1];
sum[2] += pImage->data[i+2];
}
ave[0] = unsigned char (sum[0]/n);
ave[1] = unsigned char (sum[1]/n);
ave[2] = unsigned char (sum[2]/n);
return RGB(ave[0],ave[1],ave[2]);
}
You can expand this to do std dev etc.