LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ImaQ colorImage to Array

Hello everyone, I'm working on an application where an image should be read from labview ( by a camera) and preprocessed in python function (the Image should not be read from a file path, meaning we should not save the image shown in the camera but it should be read directly in the python function and that's why I thought of sending its pixels values to the function ), for this I'm using system exec.

as a first step I was trying to read an Image from a file path to check if I can have its pixels values as an array and send it to the command line. I used the Imaq colorImage to array and to convert it to a string  I used "Flatten to string function" (since there's no 32U to string function)  but as show in the picture I'm getting strange values.
Ps: I used system exec because I don't have the licence for the other python Labview connectivity

Please if you know how can I have the array of the image pixels to send it as an argument to the python function help me, I will be so grateful ! 

Milliee_0-1653286637180.png

Milliee_1-1653286669144.png

 

0 Kudos
Message 1 of 5
(1,068 Views)
Which version of LabVIEW are you using? If you can use 2018+ I think you should have access to built-in Python nodes, no extra license needed.

Flatten to string is designed to be used with Unflatten from string in LabVIEW, I don't think you'd want to use it to send to another language. You can reshape the 2D array and convert spreadsheet string separated by tabs or commas, I don't know if there's a limit for how much data can be sent through a command line argument.
0 Kudos
Message 2 of 5
(1,019 Views)

When you acquire an Image (in LabVIEW), you get not only a set of "pixels", numeric values representing a 2D image probably internally represented as a 2D Array, plus a number of "image properties" (including height and width in pixel counts, what the Pixels encode, how many bits/pixel, other factors.  When LabVIEW writes this image to a file, say to a .png, not only are the Pixels written in some determined order, but all the image properties that allow LabVIEW, Python, ImageJ, and other software to interpret the data in the file and present an appropriate image to the viewer, can be extracted.

 

If you use LabVIEW to acquire the Image (using, say, IMAQdx Grab or Snap), you either have set up the Camera and IMAQdx to "know" (or be able to query from the Camera) all the Properties needed to use Vision functions to manipulate the Image.  If you use Python to acquire the Image from the same Camera, then other Python functions probably have access to the other information it needs.

 

But if you acquire the Image with LabVIEW, you may have difficult processing it using Python unless you can "hack" the Python "support" functions and provide the Image Properties they would have if you used Python to acquire the image.

 

The "safest" (and probably the fastest) way to "mix" LabVIEW (to acquire the Image from the Camera) and Python (to process the Image) is to use a "common intermediary":

  1. Use IMAQdx to acquire an Image from the Camera.
  2. Use Vision functions to write the Image to disk in an appropriate format (for example, "Image.png" or "Video.avi".
  3. Use Python functions to read the "transfer" function (you can use the same filename for all Images, as the file is only a "transfer" medium).
  4. Use Python functions to process the Image.

Note this requires no conversions of Images to Strings, nor requires "Flatten to String".  [I'm unsure why you do this anyway -- nothing suggests (to me) that Python expects an Image, which is largely a 2D Array of Pixels, to be in String format, 

 

Bob Schor

0 Kudos
Message 3 of 5
(999 Views)

@Bob_Schor wrote:

 

Note this requires no conversions of Images to Strings, nor requires "Flatten to String".  [I'm unsure why you do this anyway -- nothing suggests (to me) that Python expects an Image, which is largely a 2D Array of Pixels, to be in String format, 

 


In addition this almost certainly will fail catastrophically at latest when the Python executable tries to decode the parameter "string" but most likely even much earlier. There are limits in how big of parameter data you can pass through the system. Even if your parameter string won't get truncated on the way from the LabVIEW System Exec to the Python executable, Python certainly will stop at the first embedded 0 character byte as that is the way how strings are supposed to be terminated. LabVIEW doesn't care as its strings are not NULL terminated but once it passes of the data to the Windows CreateProcess() API, it has absolutely no control anymore how that data is processed and interpreted. But that flattened image would be VERY special if it doesn't contain any NULL bytes!

 

Rolf Kalbermatter
My Blog
Message 4 of 5
(988 Views)

Thank you all for replying ! Actually I finally could extract the data from the image as 2D-Array without any strange symboles, using Array shape, and then concatenated the data to build the matrix but I still have an issue, the data isn't written the same way as it is when I extract it from python ( meaning instead of being stated in the format of (R, G, B), it is stated in another long integer format) example instead of being  extracted as  [(113, 92, 73), (110, 92, 71), (108, 90, 67), etc....], it's extracted as [(7429193, 7232583, 7100995, etc....] as you can see in the front Panel, the 2D Color value array is indicating the right values but when converting the ColorValue to Integer I get other values.. I don't know if this format is considerated and read as the (R,G,B) format (which I doubt it) or maybe I'm missing something.. In the other hand I'm not sure if the system Exec can transfer all this data, but I'd love to know how I can extract the right format of image Data [( R,G,B), (R,G,B), etc...]

 

0 Kudos
Message 5 of 5
(954 Views)