Search code examples
pythonimage-processingbitmapwxpythonpixelformat

Convert Mono8 image buffer to displayable format for wx.Bitmap in wxPython Phoenix in Python


I am new to image processing.
I currently have an image buffer encoded in Mono8.

I am trying to display it using a wx.Bitmap. However, I only find documentation for RGB, RGBA or PNG.

  • Is there any way to convert a Mono8 buffer to another format displayable by a wx.Bitmap()?
  • Is there another widget able to display a Mono8 image buffer?

Solution

  • I have found how to do it:

    Mono8 is just a table of pixel's value from 0 to 255 on a grayscale.
    RGB is that same table according to other colors (Red, Green and Blue).

    So, the same image has 3 times more values in RGB than in Mono8.
    => Repeat the same value for each pixel's component.

    rgb = [ v for v in image_buffer for _ in range( 3 ) ]
    rgb_ba = bytearray( rgb )
    bitmap.FromBuffer( height, width, rgb_ba )
    

    Thanks to Martijn Pieters for the help on the list comprehension!