Search code examples
pygamegrayscaleyuv

How to get grayscale image using YUV image Pygame


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 ?


Solution

  • 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.