Python Forum
Need a little help with numpy array magic.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need a little help with numpy array magic.
#1
Hello friends,

I am struggling with an array. It's a simple array containing rgb bitmap information, as retrieved via the opencv 2 imread method. Its dimensions are (x,y,3).
I am familiar with the numpy.ndarray.flatten() function which works for 1 to 1 24 bit rgb conversion for serial transmission, but when the rgb data needs to be converted to 16 or 12 bit words, it's much easier and faster to have two 1-dimensional arrays (or lists) with (r,g,b) and (b,g,r) tuples to work with. I've tried reading values in the right order from the matrix and dumping them into a list with tuples, even converting directly from the matrix but in standard python code this is dead slow, not achieving more than 1 frame (240x240 RGB) per 3 or 4 seconds on a raspberry pi 4B.

Who can help me with the correct function to speed up the color conversion? Thank you.

P.S. this is to transmit raw color data to a small LCD display on an SPI interface, which supports 18(24), 16 and 12 bit color modes. 16 and 12 bit color modes produce higher frame rate due to the lower color bandwidth.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,910 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  IPython errors for numpy array min/max methods muelaner 1 572 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Expand the range of a NumPy array? PythonNPC 0 757 Jan-31-2023, 02:41 AM
Last Post: PythonNPC
  Change a numpy array to a dataframe Led_Zeppelin 3 1,125 Jan-26-2023, 09:01 PM
Last Post: deanhystad
  from numpy array to csv - rounding SchroedingersLion 6 2,205 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  numpy.array has no attribute head Led_Zeppelin 1 1,246 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,154 Jul-11-2022, 08:54 PM
Last Post: Larz60+
  go over and search in numpy array faster caro 7 1,770 Jun-20-2022, 04:54 PM
Last Post: deanhystad
  magic related field in Django model sonh 1 1,243 Apr-24-2022, 12:37 PM
Last Post: sonh
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,132 Apr-19-2022, 07:36 AM
Last Post: JulianZ

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020