Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 349
DRz Avatar asked Aug 31 '25 16:08

DRz


1 Answers

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!

like image 171
DRz Avatar answered Sep 02 '25 07:09

DRz