Kerwin Xiao
Kerwin Xiao

Reputation: 323

Show grayscale OpenCV image with matplotlib

I use opencv3 of python installed it by anaconda using:
conda install -c menpo opencv3=3.2.0

But when i use it to convert a picture to grayscale, like:

import cv2
import matplotlib.pyplot as plt

%matplotlib inline

image = cv2.imread('opencv_logo.png')

image1 = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

print (image.shape)
print (image1.shape)

plt.imshow(image1)

enter image description here I donnot know why:

I use windows + miniconda. Can anyone know why and help me ? Thanks.

Upvotes: 21

Views: 31642

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

You are supposed to add another parameter in plt.imshow() so as to mention that you want a gray scale image.

Modify the last line like this: plt.imshow(img, cmap='gray')

Upon doing so I got the following:

enter image description here

Upvotes: 39

Related Questions