方法一:
IplImage *pImg = ...;
int nWidth = pImg->width;
int nHeight = pImg->height;
int nChannels = pImg->nChannels;
int nStep = pImg->widthStep;
for (int i=0; i<nHeight; i++)
for(int j=0; j<nWidth; j++)
for (int k=0; k<nChannels; k++)
{
pImg->imageData[i*nStep + j*nChannels + k] = 255 - pImg->imageData[i*nStep + j*nChannels + k];
}
方法二:
IplImage *image = ...;
int div = 8;
int nl = image->height;
int nc = image->width*image->nChannels;
int step = image->widthStep;
unsigned char *data = (unsigned char *)image->imageData;
for (int i=1; i<nl; i++)
{
for (int j=0; j<nc; j+=image->nChannels)
{
data[j] += div/2;
data[j+1] += div/2;
data[j+2] += div/2;
}
data += step;
}