05-23-2022 08:25 AM
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 !
05-23-2022 01:34 PM
05-23-2022 07:34 PM
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":
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
05-24-2022 06:24 AM - edited 05-24-2022 06:25 AM
@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!
05-26-2022 06:11 PM
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...]