Created
December 21, 2018 16:37
-
-
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++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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