skipage:为什么skipage.color中的rgb2gray会产生彩色图像?

2024-04-18 04:08:59 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用以下方法将图像转换为灰度时:

from skimage.io import imread
from skimage.color import rgb2gray
mountain_r = rgb2gray(imread(os.getcwd() + '/mountain.jpg'))

#Plot
import matplotlib.pyplot as plt
plt.figure(0)
plt.imshow(mountain_r)
plt.show()

我得到了一个奇怪的彩色图像而不是灰度。

手动实现该函数也会得到相同的结果。自定义函数是:

def rgb2grey(rgb):
    if len(rgb.shape) is 3:
        return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])

    else:
        print 'Current image is already in grayscale.'
        return rgb

Original

不是灰度的彩色图像。 gray

为什么函数不将图像转换为灰度?


Tags: 方法函数from图像importreturnisplt