LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass an image into Matlab from Labview?

I am trying to pass an image into matlab from labview. To be exact, I am trying to take the image from labview, pass it into matlab, put it through a piece of matlab code which does some processing, and send the solution back to be displayed into labview. I know about the matlab script node, but I dont know how to send the image into it. So i guess my questions are

 

1) How do I pass the image into the matlab script node?

2) Does the image have to be saved in order to pass it in, or can I do it live also?

 

Attached is the VI I am using to grab the images, and the matlab code I am using to process the image.

Download All
0 Kudos
Message 1 of 8
(4,461 Views)

Matlab expects to deal with arrays, so if you plan on using the Matlab script node inside your LabVIEW code then you need to convert the image to an array of data, and you also need to make sure it's in the format expected by that function that you have. I don't know if you have just NI-IMAQ, or the full-blown NI Vision. You should check the documentation for what you have for converting an image to an array.

 

Alternatively, since you are saving the image to file, you can have the Matlab script read the file with the IMREAD function.

0 Kudos
Message 2 of 8
(4,449 Views)
Ok, assuming I can figure uot how to convert the image to an array. Your saying to just put that as the input to the script node and it should run?
0 Kudos
Message 3 of 8
(4,445 Views)
Well, the script you showed is just a function, so you would need a line of code in your Matlab script node (if you go that way) to call the function.
0 Kudos
Message 4 of 8
(4,442 Views)

Ok i put a line of code in the matlab script and nothing happens. I probed it and the image is going into the node but nothing happens.

0 Kudos
Message 5 of 8
(4,431 Views)

Here is just a simple snap that I am experimenting with. I attached the VI (which is not working). To get this straight though, as long as the function is saved on the computer, the code should work in the script node right?

0 Kudos
Message 6 of 8
(4,428 Views)
Sorry here is the Vi.
0 Kudos
Message 7 of 8
(4,427 Views)

bonesaw,

 

I assume your SpotAnalyzer is your own function, meaning you must save it to the default directory in MATLAB or set MATLAB to include it in its search path.

 

Most importantly, your code will not work because the name of the input variable to the MATLAB script node is 'image', and in your parameter to your function, there is no mentin of the variable 'image', though I am not exactly sure if your function SpotAnalyzer is a script file or a function.

 

One more important thing is that MATLAB uses double as defualt, so  you must  pass a double array to the MATLAB script, and vice versa.

0 Kudos
Message 8 of 8
(4,411 Views)