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)
I donnot know why:
I use windows + miniconda. Can anyone know why and help me ? Thanks.
To display a grayscale image in Matplotlib, we use the matplotlib. pyplot. imshow() with parameters cmap set to 'gray' , vmin set to 0 and vmax set to 255 . By default, the value of cmap , vmin and vmax is set to None .
Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2. cvtcolor() function.
Convert an Image to Grayscale in Python Using the cv2. imread() Method of the OpenCV Library. Another method to get an image in grayscale is to read the image in grayscale mode directly, we can read an image in grayscale by using the cv2. imread(path, flag) method of the OpenCV library.
matplotlib.pyplot. gray ()[source] Set the colormap to "gray". This changes the default colormap as well as the colormap of the current image if there is one.
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:
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