Hang wrote:Hi,
Morning, Hang
I'm thinking about two possible approaches:
A. With Python language bindings, I know I can do:
- Code: Select all
parameter_map = client.getInputs(unwrap=True)
# create a wrapper so we can use the Blitz Gateway.
conn = BlitzGateway(client_obj=client)
And then getting image plane:
- Code: Select all
image = conn.getObject("Image", imageId)
size_z = image.getSizeZ()
size_c = image.getSizeC()
size_t = image.getSizeT()
z, t, c = 0, 0, 0 # first plane of the image
pixels = image.getPrimaryPixels()
plane = pixels.getPlane(z, c, t) # get a numpy array.
Can I then pass/convert this numpy array to Matlab?
This is certainly what something like
mlab is trying to enable. But our experience with mlabwrap is quite old.
Or,
B. Are you suggesting me to directly use the scripts (like loadOmero.m , connectOmero.m, getImages.m ) from OMERO.matlab? Meaning establish the connection to the server in Matlab script rather than Python script. And then do the rest of the work all in Matlab script? And eventually convert the whole thing to a big Matlab executable?
This sounds most like what I had in mind during my previous answer. At the end of the day, OMERO.processor is only doing the following steps when it kicks off a Python script:
- create a temporary directory
- write a config file
- setup an environment
- launch the subprocess
You can definitely make use of the config file in the subdirectory to run a native MATLAB script which talks to the server by using the Java language binding.
As a quick aside, in case the intermediate Python layer becomes a problem, I'd add in a plan C -- the infrastructure is also in place to have OMERO.processor directly call MATLAB:
However, since we don't ship MATLAB scripts, we don't regularly test this and the syntax is much more verbose, but my assumption is that a script like the one below would work. The only thing that I needed to configure was making the
OMERO.matlab toolbox needs to be made available as if with `addpath`.
I'm not sure whether Plan A or B would be more feasible?
Comparing all three possibilities, unless you are familiar & comfortable with Python and libraries like mwrap, I'd try B or perhaps C if you're willing to try out something new.
Cheers,
~Josh
Example script:
- Code: Select all
function script(void)
[client, session] = loadOmero();
session.detachOnDestroy();
try
parse = client.getProperty('omero.scripts.parse');
if length(parse) > 0
params = javaObject('omero.grid.JobParams');
params.name = 'my-first-matlab-script' ;
params.description = 'some info';
params.stdoutFormat = 'text/plain';
params.stderrFormat = 'text/plain';
input1 = javaObject('omero.grid.Param');
input1.optional = false;
input1.description = 'A required string';
input1.prototype = javaMethod('rstring', 'omero.rtypes', '');
params.inputs = javaObject('java.util.HashMap');
params.inputs.put('input1', input1);
params = javaMethod('rinternal', 'omero.rtypes', params);
client.setOutput('omero.scripts.parse', params);
else
input1 = client.getInput('input1').getValue();
disp('Found input:');
disp(input1);
disp('Do something here');
end
catch e
client.closeSession();
rethrow e
end
client.closeSession();
end