Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
JA Builder, run Matlab code in java

Subject: JA Builder, run Matlab code in java

From: Rebecca

Date: 26 Jan, 2011 14:22:03

Message: 1 of 2

I have written an application in Matlab and compiled it into Java code using the JA builder. I'm really stuck from here as to how to integrate it into my application. How do I handle data type conversion, call the functions, etc.

The algorithm that I wrote in Matlab is for image processing, how can I pass a java buffered image to that function?

Subject: JA Builder, run Matlab code in java

From: Yair Altman

Date: 27 Jan, 2011 00:56:03

Message: 2 of 2

"Rebecca" wrote in message <ihpamb$acv$1@fred.mathworks.com>...
> I have written an application in Matlab and compiled it into Java code using the JA builder. I'm really stuck from here as to how to integrate it into my application. How do I handle data type conversion, call the functions, etc.
>
> The algorithm that I wrote in Matlab is for image processing, how can I pass a java buffered image to that function?

There are all sorts of direct interfaces possible but the easiest and safest approach is to simply write the BufferedImage to file in some standard format, then read this file in Matlab.

For a more direct approach read http://www.mathworks.com/support/solutions/en/data/1-2WPAYR/index.html

An equivalent but much faster variant of the above, courtesy of Jan Simon:

pixelsData = reshape(typecast(jImage.getData.getDataStorage, 'uint8'), 4, w, h);
imgData = cat(3, ...
        transpose(reshape(pixelsData(3, :, :), w, h)), ...
        transpose(reshape(pixelsData(2, :, :), w, h)), ...
        transpose(reshape(pixelsData(1, :, :), w, h)));

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us