performanceloopsindexinglabviewshift-register

How to quickly unpack U32 Image Array into an RBG U8 Array in LABVIEW


I have a flattened (1D) U32 encoded image array which has r, b, and b 8-bit channel values encoded into the first 24 bits of each U32. I would like to expand this array into and array of U8s that each store a separate r, g, or b value (0-255). The issue is that I need this to happen really fast (hundreds of times per second on an old computer) and the method I created is slow.

I am a novice at labview, so I am not exactly sure what a faster way to do this is.

I have successfully accomplished this by creating a U8 array, iterating through each index of the U32 Image array and assigning the corresponding 3 rgb values to the appropriate index in the U8 array using a shift-register. I attempted to use the In Place Element Structure (which would presumably not require copying data in between loops like shift), but I did not know how to make it work inside the loop and when I tried to return the last array from the loop, only the last element was modified.

Here is the first, working method I described above:

dropbox VI image link (update i have reputation now)

In c/c++, it would be pretty simple (something like this):


uint8_t* convert_img(uint32_t img[640*480]){
  uint8_t *img_u8 = new uint8_t[640*480*3];
  for (int i=0; i<640*480; ++i){
    img_u8[i*3] = img[i] & 0xff; // r
    img_u8[i*3 + 1] = (img[i] >> 8) & 0xff; // g
    img_u8[i*3 + 2] = (img[i] >> 16) & 0xff; // b
  }
  return img_u8;
}

The working labview example above only runs at 20 Hz! I think this is super slow for such a simple operation. Does anyone with more experience have a suggestion of how I can make this happen quickly with labview code?


Solution

  • I would do it like this: U32 to U8

    enter image description here

    The steps are:

    Should be plenty fast enough.