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
You can also use scikit-image, which provides some functions to convert an image in ndarray
, like rgb2gray
.
from skimage import color
from skimage import io
img = color.rgb2gray(io.imread('image.png'))
Notes: The weights used in this conversion are calibrated for contemporary CRT phosphors: Y = 0.2125 R + 0.7154 G + 0.0721 B
Alternatively, you can read image in grayscale by:
from skimage import io
img = io.imread('image.png', as_gray=True)