Processing image bits in Python

I have an application that gets a pointer to JPEG data from a camera API wrapped in ctypes, converts it to wx.Image and displays the images as a movie.

One of the necessary functions is to set two pixel components equal to the third. For example, my RGB pixel is (100,225,255), I want to set R and B to G, or (200,200,200). I need to make it t for each pixel in the image, while maintaining an acceptable frame rate.

I can access the RGB values ​​from my wx.Image by calling Image.GetData, which returns a string containing the pixel values ​​in the following format: RGBRGBRGB ... I implemented the function naively by iterating through this string RGBRGBRGB,

However, this naive approach is too slow to achieve a decent FPS, because (I think):

a) I repeat every pixel of the image.

b) I am doing too much data copying.

I decided to convert my RGB data to numpy by doing the operation (I assume numpy will have a faster way to do such things) and then convert back to wx.Image. Unfortunately, I cannot convert directly from raw data to numpy, because the data comes in as a JPEG, not as an RGB bitmap. So I need to go from data-> wx.Image-> numpy array-> wx.Image.

python, , , G- R B . , , , , . C? ?

, , ? numpy buffer, , ?

/ , - , :)

+3
2

Python Imaging Library (PIL) - .

wxPython PIL , jpeg PIL.

wx- PIL, , , ( ):

r, g, b = im.split()              # split the image into separate color planes
im = Image.merge("RGB", (g, g, g))  # merge them back, using the green plane for each

wxPython.

, Python, PIL C .

+1

, GLSL OpenGL PyGame. , . ( C), RenderMonkey - it IDE!

!

+1

Source: https://habr.com/ru/post/1761791/


All Articles