OpenCV image conversion from RGB to Grayscale using imread giving poor results

前端 未结 3 1377
梦毁少年i
梦毁少年i 2021-01-01 17:49

I\'m loading a 24 Bit RGB image from a PNG file into my OpenCV application.

However loading the image as grayscale directly using imread gives a very po

3条回答
  •  清歌不尽
    2021-01-01 18:13

    I was having the same issue today. Ultimately, I compared three methods:

    //method 1
    cv::Mat gs = cv::imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
    
    //method 2
    cv::Mat color = cv::imread(filename, 1); //loads color if it is available
    cv::Mat gs_rgb(color.size(), CV_8UC1);
    cv::cvtColor(color, gs_rgb, CV_RGB2GRAY);
    
    //method 3
    cv::Mat gs_bgr(color.size(), CV_8UC1);
    cv::cvtColor(color, gs_bgr, CV_BGR2GRAY);
    

    Methods 1 (loading grayscale) and 3 (CV_BGR2GRAY) produce identical results, while method 2 produces a different result. For my own ends, I've started using CV_BGR2GRAY.

    My input files are jpgs, so there might be issues related to your particular image format.

提交回复
热议问题