How can I convert an RGB image into grayscale in Python?

前端 未结 12 1116
Happy的楠姐
Happy的楠姐 2020-11-22 04:43

I\'m trying to use matplotlib to read in an RGB image and convert it to grayscale.

In matlab I use this:

img = rgb2gray(imread(\'image.p         


        
12条回答
  •  花落未央
    2020-11-22 04:48

    The fastest and current way is to use Pillow, installed via pip install Pillow.

    The code is then:

    from PIL import Image
    img = Image.open('input_file.jpg').convert('L')
    img.save('output_file.jpg')
    

提交回复
热议问题