LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert an Image to a 3D Array (Rows × Columns × Channels) in LabVIEW Vision Development Module for Deep Learning Model Input

Solved!
Go to solution

Hi everyone,

I'm working in LabVIEW using the Vision Development Module (VDM) and I want to use the Load Pretrained Model (.pb) option to perform inference with a TensorFlow model.

The model expects an input in the form of a 3D array with the format:
[Rows][Columns][3] (i.e., a color image with 3 channels — RGB).

I can read and display images using IMAQ ReadFile, but I'm unsure how to convert this image into the required 3D array format suitable for deep learning model input.

What I Need:

How do I convert a color image into a 3D array with shape [Height][Width][3] in LabVIEW?

What I’ve Tried:

  • Loaded the image using IMAQ ReadFile.

  • Used IMAQ ColorImageToArray, which gives a 2D array of clusters containing RGB values.

  • I need help splitting those RGB values and reconstructing a 3D array where the third dimension is the color channel.

If anyone has done this before or can suggest the best way to achieve this in LabVIEW (2019), I would appreciate detailed steps or a block diagram.

Thanks in advance!

0 Kudos
Message 1 of 8
(288 Views)
Solution
Accepted by topic author sasimitha

You can use IMAQ IntegerToColorValue VI to get color components, something like this:

snippet1.png

Result:

Screenshot 2025-05-12 10.43.38.png

Message 2 of 8
(256 Views)

 

I am working with a deep learning model that takes a color image as input. Before feeding the image to the model, I normalize the pixel values to be in the range [0, 1]. The input format is flattened and fed to the model accordingly.

After inference, the model returns a 1D array of float values, also normalized between 0 and 1. Each group of three values in this array represents the R, G, B components of a single pixel. For example:

  • output[0:3] → RGB values of the 1st pixel

  • output[3:6] → RGB values of the 2nd pixel

  • and so on...

Now I want to reconstruct the image and display it in LabVIEW. What is the best way to:

  1. Convert this 1D array into a 3D RGB image array (e.g., [height, width, 3])

  2. Scale the pixel values back to [0, 255] (U8 format)

  3. Display the image using standard LabVIEW image display tools (like IMAQ image)

Any guidance or example VIs would be greatly appreciated!

Download All
0 Kudos
Message 3 of 8
(191 Views)

Hello,

I have a 1D NumPy array of size 49152, which is the output from my deep learning model. This corresponds to an RGB image of size 128×128 with 3 channels (i.e., 128 × 128 × 3 = 49152).

The array is structured such that:

  • The first 3 values represent the RGB values of the first pixel,

  • The next 3 values are for the second pixel, and so on.

I would like to convert this 1D array back into a proper color image 

How can I do this

Thanks in advance!

Download All
0 Kudos
Message 4 of 8
(118 Views)

Hello,

I have a 1D NumPy array of size 49152, which is the output from my deep learning model. This corresponds to an RGB image of size 128×128 with 3 channels (i.e., 128 × 128 × 3 = 49152).

The array is structured such that:

  • The first 3 values represent the RGB values of the first pixel,

  • The next 3 values are for the second pixel, and so on.

I would like to convert this 1D array back into a proper color image 

How can I do this

Thanks in advance!

Download All
0 Kudos
Message 5 of 8
(124 Views)

Hi sasimitha,

 


@sasimitha wrote:

I have a 1D NumPy array of size 49152, which is the output from my deep learning model. This corresponds to an RGB image of size 128×128 with 3 channels (i.e., 128 × 128 × 3 = 49152).

The array is structured such that:

  • The first 3 values represent the RGB values of the first pixel,

  • The next 3 values are for the second pixel, and so on.

I would like to convert this 1D array back into a proper color image 

How can I do this


  • Those array values are floats, but RGB data typically are integer values. LabVIEW uses them with an U8 datatype, so values range from 0 to 255. You need to scale your RGB data accordingly…
  • LabVIEW has a "RGB values to color" function to convert three U8 values to a color value…
  • You can reshape your 1D array into a 2D array of 16384*3 elements. Now autoindex each 3 elements and convert them to color. Reshape the resulting 1D array of 16384 elements to your 2D array of 128*128 pixels (aka color values)…
  • Use the 2D picture functions to display your pixel data…

What have you tried and where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 8
(99 Views)

According to the documentation of IMAQ DL Model Run VI, you use the dimension output to reshape the flat array. Then I imagine you use IMAQ ArrayToColorImage VI to convert it to an image, but I do not have experience with the vision module.

 

snip.png

0 Kudos
Message 7 of 8
(81 Views)

I threw this together (but didn't try it out).  Let me know if it works.

Untitled.png

0 Kudos
Message 8 of 8
(52 Views)