Skip to content

Instantly share code, notes, and snippets.

@lMooka
Created February 13, 2013 05:00
Show Gist options
  • Save lMooka/4942406 to your computer and use it in GitHub Desktop.
Save lMooka/4942406 to your computer and use it in GitHub Desktop.
unsigned char* copyGrayImage(unsigned char* img, int w, int h) {
unsigned char* imgCpy = (unsigned char*) malloc ( sizeof(unsigned char) * w * h);
int i,j;
if (imgCpy != NULL)
for (j = 0 ; j < h ; j++)
for (i = 0 ; i < w ; i++)
imgCpy[j*w+i] = ( 0.3*img[j*w*3+i*3+RED] +
0.59*img[j*w*3+i*3+GREEN] +
0.11*img[j*w*3+i*3+BLUE]);
return imgCpy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment