skimage:为什么来自skimage.color的rgb2gray会产生彩色图像?

kwo*_*sin 21 python image-processing scikit-image

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

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()
Run Code Online (Sandbox Code Playgroud)

我有一个奇怪的彩色图像而不是灰度.

手动实现该功能也给了我相同的结果.自定义功能是:

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
Run Code Online (Sandbox Code Playgroud)

原版的

彩色图像不是灰度. 灰色

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

Ton*_*wer 30

生成的图像为灰度.但是,imshow默认情况下,使用一种热图(称为vidris)来显示图像强度.只需指定灰度色彩图,如下所示:

plt.imshow(mountain_r, cmap="gray")

对于所有可能的色彩映射,请查看色彩映射参考.