-
-
Save waltman/60077c507c54150b68e4d44d856d8270 to your computer and use it in GitHub Desktop.
Attempt at creating a Matlab figure from ImageJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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