Search code examples
matplotlibimage-processinggrayscale

OpenCV is not graying an image with cv2.cvtColor when displayed with matplotlib


I tried to gray an image but it does not work properly like it should. It just applied a kind of filter as you can see by using cv2.COLOR_BGR2GRAY function. Kindly someone help me to get over with this issue.

1


Solution

  • Your issue is that you're using matplotlib to show your grayscale image. Matplotlib applies a colormap. By default that's a colorful one.

    Add cmap="gray" in your imshow call: plt.imshow(img_gray, cmap="gray")