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.