Skip to content

Instantly share code, notes, and snippets.

@waltman
Created October 18, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waltman/60077c507c54150b68e4d44d856d8270 to your computer and use it in GitHub Desktop.
Save waltman/60077c507c54150b68e4d44d856d8270 to your computer and use it in GitHub Desktop.
Attempt at creating a Matlab figure from ImageJ
import ij.*;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import com.mathworks.engine.MatlabEngine;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
public class Demo_Figure implements PlugInFilter {
Future<MatlabEngine> engFuture;
MatlabEngine eng;
public Demo_Figure() {
try {
engFuture = MatlabEngine.startMatlabAsync();
} catch (Exception e) {
IJ.log(String.format("exception! %s", e));
}
}
public int setup(String arg, ImagePlus imp) {
if (IJ.versionLessThan("1.37j"))
return DONE;
else
return DOES_ALL+DOES_STACKS+SUPPORTS_MASKING;
}
public void run(ImageProcessor ip) {
try {
// Display the image in a Matlab figure
float[][] imf = ip.getFloatArray();
eng = engFuture.get();
Future<Double> future = eng.fevalAsync("factorial", (double) 10);
double d = future.get();
IJ.log(String.format("10! = %f", d));
eng.putVariableAsync("im", imf);
eng.fevalAsync("figure"); // this is the line that kills ImageJ
} catch (Exception e) {
IJ.log(String.format("exception! %s", e));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment