python imshow彩色_plt.imshow显示了IPython中灰度图像的彩色图像

I have the following RGB image 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)

I convert this to a grayscale image imGray

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

imGray.shape

>>(128L, 128L)

#plotting

plt.imshow(imGray)

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

解决方案

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")

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值