These are chat archives for fiji/fiji

Oct 2018
Kyle I S Harrington
Oct 11 2018 01:58
@ctrueden it should be the latter, you don't need new to invoke a java constructor from matlab (ran into this for some backdoor clojure<->matlab interfacing sometime back)
Curtis Rueden
Oct 11 2018 02:08
Thanks @kephale.
Szabolcs Horvát
Oct 11 2018 09:17
Hi @ctrueden and thanks for the tips! I have seen those tutorials. They show how to use the Ops framework, which seems to be designed for easy scripting use. It would be the ideal thing.
But the MATLAB interface doesn’t seem to work with the same kinds of images (same class?) as the one shown there. It just puts up images in GUI windows, or retrieves them from GUI windows. I’m not sure how to get a handle to the image I sent from MATLAB with e.g. and do operations on it with the Ops stuff.
I don’t actually need to show the images in a GUI window. I just need to apply filters to them.
If I could figure out how to convert a MATLAB matrix to the specific image class that works with the Ops stuff, and how to convert that back to a MATLAB matrix, then I think I’d be done.
Szabolcs Horvát
Oct 11 2018 09:23
I should note that I am new to ImageJ and I don’t (yet) know any Java ...

I should also note that what I actually want is interfacing ImageJ not with MATLAB but with Mathematica. However, Mathematica’s Java interface does not seem to be powerful enough to allow this. The workaround: control MATLAB from Mathematica (I wrote a package for this), and control ImageJ from MATLAB. This solution looks very promising.

However, if there might be an easier and still flexible way to control ImageJ from another system (e.g. if there are command line tools), that might be a better approach. If not, going through MATLAB looks to be the best.

Szabolcs Horvát
Oct 11 2018 09:29
Also pinging @hinerm since you are the author of the MATLAB interface.
Szabolcs Horvát
Oct 11 2018 11:56
I made some progress on this. Here’s a concrete stumbling block I can’t get through:
Szabolcs Horvát
Oct 11 2018 12:02
The setup phase works.
addpath /Applications/

load durer
im = X/128;
I am trying to follow the tutorial that @ctrueden linked to, specifically apply a median filter to an image.
Now we try to use ImageJ through the Ops framework:
ij = net.imagej.ImageJ(IJM.context());
ijIm = copytoImg(im)
neighborhood = net.imglib2.algorithm.neighborhood.HyperSphereShape(4)
median = ij.op().run('create.img', ijIm)
So far so good.
Now I try ij = net.imagej.ImageJ(IJM.context());, which fails with "No method 'run' with matching signature found for class 'net.imagej.ops.DefaultOpService'." This is trying to be the MATLAB-syntax equivalent of the line ij.op().run("filter.median", median, eyes32, neighborhood) from the tutorial.
Szabolcs Horvát
Oct 11 2018 12:10
I was also trying to write the equivalent of topHat = ij.op().morphology().topHat(eyes, [neighborhood]), but I can't figure out how to put neighborhood in a "list" in MATLAB. What MATLAB data structure converts to a "list"? A cell array doesn't seem to.
Curtis Rueden
Oct 11 2018 15:52

@szhorvat wrote:

No method 'run' with matching signature found for class 'net.imagej.ops.DefaultOpService'.

I think you are running into a MATLAB limitation regarding calling Java methods with varargs syntax.

See here for a workaround.
The run method of ops is run(String opName, Object... args). Which is the same thing as run(String opName, Object[] args) signature-wise, except that Java allows you to list a variable number of arguments and then smooshes them into an Object[] (array) under the hood. But I guess MATLAB is not smart enough to do that.
args = javaArray('java.lang.Object',3);
args(1)= median;
args(2)= eyes32;
args(3)= neighborhood;
median = ij.op().run('create.img', args)
Maybe something like the above?
Szabolcs Horvát
Oct 11 2018 16:28
Thank you @ctrueden , it works
Curtis Rueden
Oct 11 2018 16:40
@szhorvat Awesome! :+1:
Please feel welcome to edit the MATLAB_Scripting page to add this information!
Szabolcs Horvát
Oct 11 2018 18:51
@ctrueden I did not know that outsiders could edit. Once I get more confortable with it, and I actually manage to solve my main task, I will add a few educational examples to the wiki.
Curtis Rueden
Oct 11 2018 19:12
@szhorvat Awesome, thank you. Yes, to edit, just scroll to the bottom of any page and click "Create account" to make a wiki account.