plt.imshow显示了IPython中灰度图像的彩色图像 [英] plt.imshow shows color images for grayscale images in IPython

查看:4661
本文介绍了plt.imshow显示了IPython中灰度图像的彩色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下RGB图片 imRGB

import cv2
import matplotlib.pyplot as plt

#Loading the RGB image
imRGB = cv2.imread('*path*')

imRGB.shape
>>(128L, 128L, 3L)

#plotting
plt.imshow(imRGB)

我将此转换为到灰度图像 imGray

imGray = cv2.cvtColor(imRGB, cv2.COLOR_BGR2GRAY)

imGray.shape
>>(128L, 128L)

#plotting
plt.imshow(imGray)

问题:为什么是灰度图像 imGray 以彩色显示?

Question: Why does the grayscale image imGray is shown in color?

推荐答案

imRGB是一个3D矩阵(高x宽x 3)。

现在imGray是一个2D矩阵,其中没有颜色,只有光度值。
因此matplotlib默认应用了一个色彩映射。

imRGB was a 3D matrix (height x width x 3).
Now imGray is a 2D matrix in which there are no colors, only a "luminosity" value. So matplotlib applied a colormap by default.

阅读此页面并尝试要应用灰度色彩图或不同的色彩图,请检查结果。

Read this page and try to apply a grayscale colormap or a different colormap, check the results.

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

使用此页面作为参考用于colormaps。某些色彩映射无法正常工作,如果发生则尝试另一个色彩映射。

Use this page as reference for colormaps. Some colormap could not work, if it occurs try another colormap.

这篇关于plt.imshow显示了IPython中灰度图像的彩色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆