0

I am trying to learn Pygame and I wanted to start from something simple. I just stuck on eliminating U and V channel from image to get a grayscale image.

cam = pygame.camera.Camera(self.clist[0], self.size, "YUV") 

What is the way to do it ?

hma
  • 556
  • 2
  • 11
  • 29

1 Answers1

0

If you can use the PIL/pillow library, you can convert the pygame image into a PIL image, perform the grayscale conversion there, and convert back. This conversion is illustrated here. Alternatively, you can just use the solution posted here that manually transforms the data to grayscale.

Community
  • 1
  • 1
CodeSurgeon
  • 2,435
  • 2
  • 15
  • 36
  • Thank you for help the second link works fine but is there a way to do that if you recording the picture as YUV format – hma Nov 10 '16 at 14:42
  • With YUV, the Y component is the luminance, so you can use that for the R, G, and B components of the surface array. If R = G = B, you should get a grayscale image, so just make Y = R = G = B. – CodeSurgeon Nov 12 '16 at 02:48
  • Thank you for the explanation @user2588654 – hma Nov 14 '16 at 17:06