Revision history [back]

If you are not interested by a color image (ie you only want to convert color image into grayscale) and to avoid testing all values (RGB, RGBA, etc), you could directly load your image in grayscale:

cv::Mat image = cv::imread( "myImage.jpg/png/...", 0 );


The mat 'image' will be in grayscale. See the doc of imread for more information.

If you are not interested by a color image (ie you only want to convert color image into grayscale) and to avoid testing all values (RGB, RGBA, etc), you could directly load your image in grayscale:

cv::Mat image = cv::imread( "myImage.jpg/png/...", 0 CV_LOAD_IMAGE_GRAYSCALE );


The mat 'image' will be in grayscale. See the doc of imread for more information.