LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert 11bit binary array to image

Is there a way to solve following code section more efficiently? Every time I start the case my program runs only with a fraction of the speed it used to.
The input is a 16 bit integer 2d-array which I then convert in the loop into the corresponding 11 bit binary string. Now I extract the RGB values of this string and let the user manipulate them with a scale.
Then i reverse all the steps and print the 2d array with a resolution of 640x480 pixels on the Image.

help (1).PNG

0 Kudos
Message 1 of 4
(875 Views)

Hi vaiosc,

 


vaiosc@gmx.de wrote:

Is there a way to solve following code section more efficiently?


Yes!

Whenever you convert numbers to string and back to numbers just to manipulate some bits then there is a simpler way…

 

Suggestion to get your RGB bits:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(866 Views)

Hi vaiosc,

 

suggestion for the other conversion from RGB values to U16:

Make sure the RGB values are within valid ranges (0…7 or 0…31)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 4
(826 Views)

vaiosc@gmx.de wrote:

Every time I start the case my program runs only with a fraction of the speed it used to.


Gerd already gave you great advice so listen to him carefully.

 

Still, I am curious that you said that the same code used to run faster. That is very hard to believe! How did you measure the speed? What was the speed before and after?

 

As has been said, doing bit manipulations using binary formatted strings and orange(!) math is just really (really!!!) bad!

 

Some other observations:

  • Code is not scalable, because you reshape to a fixed number instead of reshaping to the product of the dimensions of the 2D array, then you reshape to 640x480 instead of the original size. This means that if you ever need to deal with other sizes in the future, the code needs to be rewritten.
  • You have three controls inside the loop, meaning that the compiler needs to assume that they can change at any time and cannot do certain optimizations (folding) because these terminal cannot be considered invariant and need to get read with every iteration, i.e. millions of times!
  • How many "255" diagram constants do you really need? One is probably sufficient. Branching wires is allowed.
  • Gerd already showed you how to process a scalar. It might be possible to apply the same math to the 2D array directly. Not sure.

 

When asking for help, you need to attach your VI (preferably LabVIEW 2020 or lower) AND some typical data. This way we can actually test that our solutions give the same result (but are just millions of times faster!). Nobody in his right mind would try to reconstruct the code in your image from scratch, especially since we don't even know the values of the controls (well, we can guess, of course).

 

 

0 Kudos
Message 4 of 4
(797 Views)