Show black and white OpenCV image with matplotlib

I am using opencv3 python installed by anaconda using:
conda install -c menpo opencv3=3.2.0

But when I use it to convert the image 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 do not know why:

I am using windows + miniconda. Anyone can know why and help me? Thank.

+3


source to share


1 answer


You have to add one more parameter in plt.imshow()

to mention that you want a grayscale image.

Change the last line as follows: plt.imshow(img, cmap='gray')



After that I got the following:

enter image description here

+5


source







All Articles