I have this following function to plot any image.
def draw_image(img, title, height, width):
plt.figure(figsize = (height,width))
plt.title(title)
imgplot = plt.imshow(img)
Now I want to plot a normal RGB image and its Grayscale version using this function. I have used the rgb2gray() function from scikit-image to convert the main image into grayscale. Then I have sent both of them to the function I previously mentioned. I have written this code.
grayscale = rgb2gray(img)
draw_image(img, "Original", 5, 5)
draw_image(grayscale, "Grayscale", 5, 5)
But surprisingly this produces the following images.
This is not what I expected. This has not produced a correct grayscale image. So I have tried to change my code a bit. I have changed the function a bit. The changed function looks like this.
def draw_image(img, title, height, width):
plt.figure(figsize = (height,width))
plt.title(title)
imgplot = plt.imshow(img, 'gray')
Now this two pictures have been produced.
Though this code is producing the correct output, I cannot understand what is going on. Why did the first function produce such a greenish image as grayscale? Why did the second one produce the actual grayscale image? Why is the original image at both cases same? Is there anything wrong with rgb2gray function? Can anyone explain the right procedure to show an image and convert it into a grayscale image?