尝试在imageJ中运行Jython插件时出现语法错误。
Java以
开头import ij.plugin.filter.PlugInFilter;
import ij.ImagePlus;
import ij.process.ImageProcessor;
import org.python.util.PythonInterpreter;
public class Invert_Filter implements PlugInFilter {
public int setup(String arg, ImagePlus imp) {
// inform ImageJ that this plugin filter only handles 8 bit grayscale images
return DOES_8G;
}
public void run(ImageProcessor ip) {
// create a Python interpreter
PythonInterpreter py = new PythonInterpreter();
// pass the image processor of the current image to the Python interpreter
py.set("ip", ip);
// execute the Python file containing the source code for this ImageJ plugin filter
py.execfile("C:\\ImageJ\\plugins\\Invert_Filter.py");
}
}
和Python代码:
# "ip" is the image processor of the current image that is passed in from ImageJ
ip.invert()
运行时,我得到:
NameError:名称'ip'未定义