1

I am using pygame to show grayscale images. However, it can't show grayscale image, the output is here

enter image description here

The images are numpy arrays of which shape is 80X80, and the code is here

surf_1 = pygame.surfarray.make_surface(pic_1)
surf_2 = pygame.surfarray.make_surface(pic_2)
surf_3 = pygame.surfarray.make_surface(pic_3)
surf_4 = pygame.surfarray.make_surface(pic_4)

self.screen.blit(surf_1, (120, 40))
self.screen.blit(surf_2, (210, 40))
self.screen.blit(surf_3, (300, 40))
self.screen.blit(surf_4, (390, 40))

My question is how can I show real grayscale images instead of the blue-green one.

Update

Here is the code to convert RGB to grayscale, it is from the Internet, I don't know the exact source, sorry about that.

def rgb2gray(rgb, img_shape):
    gray = np.dot(rgb[..., :3], [0.299, 0.587, 0.114])
    return gray.reshape(*img_shape)
GoingMyWay
  • 16,802
  • 32
  • 96
  • 149
  • Can you show us the code that you use to convert the images to grayscale? – skrx Aug 27 '17 at 09:59
  • @skrx, I updated the question. If you use matplotlib to show image, if you did add `cmap=plt.cm.gray`, the same issue occurs. `plt.imshow(gray_img, cmap=plt.cm.gray)` can show the grayscale image. – GoingMyWay Aug 27 '17 at 10:04
  • Check out the `grayscale` function in [this answer](https://stackoverflow.com/a/10693616/6220679). – skrx Aug 27 '17 at 11:56
  • @skrx, I don't think it is the grayscale function makes this issue happens. However, if you use `plt.imshow ` function without `cmap=plt.cm.gray`, the same issue occurs again even with `matplotlib` – GoingMyWay Aug 27 '17 at 12:57

0 Answers0