views:

108

answers:

3

I have a problem with transferring the image (RGB data) I get from Java GUI (for which I have the source code) to a MATLAB array. Can this be done?

I don't know where to start since I'm not very familiar with Java programming. Any help would be appreciated. I'm a Ph.D. student and I need to solve this for my future research.

A: 

Well, if you haven't got any better ideas, use a screen grabber (Alt+PrntScreen on Windows, whatever on Linux) and paste the grab into MS Paint or GIMP. Then save in your favourite image file format and bob's your uncle.

Or, am I as usual, missing some incredible complication ?

If that's too simple, modify the Java to write the image to a file -- you say you have the source. You could even have Matlab call the Java to do that, then retrieve the image directly.

High Performance Mark
+1  A: 

Since you are in Java there are a few things that can happen here.

1) Use the MATLAB Builder JA. This will allow you to create a Java layer that allows you to marshal data from within Java into the MATLAB runtime. Note that this option has other requirements that I talk about here

2) You can write out the image in Java into one of the image formats that MATLAB understands and then load it using the aforementioned imread

3) And this is a dubious solution, but will work. Write out the image as a matrix in CSV format. You can then load that into MATLAB and it will convert the CSV into a multidimensional matrix which is more or less the representation of the image

Basically it breaks down into writing out the image data in some format that MATLAB understands or write an interop layer.

linuxuser27
Matlab Builder JA is not required in order to access the image data.
zellus
@zellus. Yes, as your solution mentions you could do all this from within the MATLAB environment however then you have to also run the entire CmuCam2 application from within MATLAB, but this is an option that should be considered.
linuxuser27
Thank you all for help.I thing that first solution can be used, since I have to transfer the data in real time. I can't save the image I get on the disk.At first, I can start the gui from matlab, but the ideal solution is to control the gui functions without gui opening. Can this be done with builder ja?
Mare
This can technically be done as zellus mentions. You are able to instantiate Java objects at MATLAB command prompt. If you know the Java objects that are used to generate the object in question you can script the method calls to the Java objects. See http://www.mathworks.com/help/techdoc/matlab_external/f4863.html. Build JA can be used to create a distributable solution when you finalize your process.
linuxuser27
Ok, thank you again. I'll let you know what I manage to do in a day or two.
Mare
A: 

One of the outstanding capabilities of MATLAB is its Java scripting capability. As you can download CmuCam2 sources, you just instantiate the Java classes you need and call the required methods as they were MATLAB built-in functions.

Have a look at "Bringing Java Classes and Methods into MATLAB Workspace" of The MathWorks documentation.

zellus