Skip to content

Instantly share code, notes, and snippets.

@SubhiH
Created December 21, 2018 16:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SubhiH/b34e74ffe4fd1aab046bcf62b7f12408 to your computer and use it in GitHub Desktop.
Save SubhiH/b34e74ffe4fd1aab046bcf62b7f12408 to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale by looping through pixels using char raw pointers C++
void ImageOperator::to_gray(const unsigned char* bgr_input,
const int width,
const int height,
const int channel,
unsigned char* gray_output){
int index = 0;
int step = channel*width;
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width*channel; col+=channel) {
gray_output[index] = 0.11*bgr_input[row*step+col]+
0.59*bgr_input[row*step+col+1]+
0.3*bgr_input[row*step+col+2];
index++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment