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

问题描述 投票:19回答:1

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

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

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

python image-processing scikit-image
1个回答
25
投票

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

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

对于所有可能的色彩映射,请查看colormap reference

© www.soinside.com 2019 - 2024. All rights reserved.