My intention is to use matplotlib to convert a coloured image into a grayscale image and use colormap to display it in the Viridis scale.
The code for that is as follows:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
IMG = mpimg.imread('dog_1.jpg')
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140])
gray = rgb2gray(IMG)
plt.imshow(gray, cmap='viridis')
plt.show()
The output displayed is proper and as follows: Output Image
Now, I want to save the output image in a variable as a numpy array to carry out further processing. Can I do it in any way?