18

I am doing my first steps using OpenCV (version 3.3.0 from opencv-python package on Mac OS). Using OpenCV inside jupyter notebook and displaying a greyscale image through matplotlibresults in a greenish image instead of a greyscale one.

%matplotlib inline

import cv2 as cv
import numpy as np

import matplotlib.pyplot as plt

plt.rcParams['figure.figsize'] = (8.0, 8.0)

img = cv.imread('IMG_20171212_222022.jpg', cv.IMREAD_GRAYSCALE)

plt.imshow(img)

greenish image from jupyter notebook

Do you know where this comes from? Is this a bug or desired behavior?

albert
  • 8,027
  • 10
  • 48
  • 84
  • Seems like you are getting a colormap based on the grayscale values. I'm not familiar with the OpenCV Python interface- but that's where I'd start looking. – Adi Shavit Dec 12 '17 at 22:29
  • 6
    This is not about OpenCV, you're calling [`imshow`](https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.imshow.html) from Matplotlib, which uses a colormap when displaying single channel images. Just [pick one](https://matplotlib.org/tutorials/colors/colormaps.html) that's more appropriate... – Dan Mašek Dec 12 '17 at 22:55
  • 27
    plt.imshow(img, cmap = plt.cm.gray) – Robbie Dec 13 '17 at 01:19

0 Answers0