Kaiming
Kaiming

Reputation: 183

Why do I get a green image when I convert an RGB image to grayscale using OpenCV?

When I tried to convert an RGB image with OpenCV function cv2.cvtColor(), I got a green-like image.

I've converted the raw image read by OpenCV to RGB-format, again converted it to gray scale using cv2.cvtColor(), and tried to display it using pyplot.imshow() function.

image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
plt.imshow(image)

Upvotes: 10

Views: 12372

Answers (1)

lenik
lenik

Reputation: 23498

plt.imgshow() uses a color map for a single-channel images. You have two possible solutions, convert your grayscale to rgb (basically duplicate the grayscale 3 times), or choose a proper colormap as explained here: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

linear colormaps

Upvotes: 6

Related Questions