Sorry if duplicate - I can't convert an RGB (or BGR) image to grayscale using OpenCV in Google Colab
I've recently switched from using OpenCV in C++ to Python and have been using Google Colab (OpenCV version 3.4.3) for some basic image manipulation, I want to input an image and convert it to grayscale to perform some thresholding. I've learned that you can't use cv2.imshow on Colab and instead have been using pyplot.imshow which requires changing the format of the image from BGR to RGB.
I was following this tutorial notebook which is very helpful but using the same code on the same image produces a different output - my 'grayscale' image is green/yellow/blue compared to the actual grayscale output achieved in the tutorial.
# read input image in BGR format
orig = cv2.imread('./20.png')
# convert from BGR to RGB
rgb = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB)
# convert from RGB to gray using cv2.COLOR_RGB2GRAY
gray1 = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
print("Input image")
plt.imshow(orig)
plt.show()
print("\nRGB image")
plt.imshow(rgb)
plt.show()
print("\nGrayscale image: RGB2GRAY conversion")
plt.imshow(gray1)
plt.show()
Outputs 1 and 2 (input image and RGB image) are as expected but the grayscale image is green/yellow/blue instead of black and white