Detect if image is color, grayscale or black and white with Python/PIL

后端 未结 5 716
青春惊慌失措
青春惊慌失措 2020-12-24 09:06

I extract pages images from a PDF file in jpeg format and I need to determine if each image is much more grayscale, color ou black and white (with a tolerance factor).

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 09:47

    You can use the cv::Mat::channels() operator and that can tell you whether it is a "grayscale" (i.e., 2 channel) or "color" (i.e., 3-channel) image. For black and white, you will need set deeper tests based on grayscale since the definition varies.

提交回复
热议问题