How to check whether a jpeg image is color or gray scale using only Python stdlib

前端 未结 9 2136

I have to write a test case in python to check whether a jpg image is in color or grayscale. Can anyone please let me know if there is any way to do it with out installing e

9条回答
  •  失恋的感觉
    2020-12-24 13:32

    Can be done as follow:

    from scipy.misc import imread, imsave, imresize
    image = imread(f_name)
    if(len(image.shape)<3):
          print 'gray'
    elif len(image.shape)==3:
          print 'Color(RGB)'
    else:
          print 'others'
    

提交回复
热议问题