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?
The most direct way is to just render your array to RGB using the colormap, and then change the pixels you want.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With