可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am using Python to design a software, and the image processing is one of the steps. I am using ImageJ to realize this.
Since there is a Jython interpreter within ImageJ, which can be opened within ImageJ software, there must be a way to connect ImageJ to Python and call all the functions within Python.
I wonder how I can do that to finish all the processing in Python rather than open the interpreter in ImageJ?
回答1:
I wonder how I can do that to finish all the processing in Python rather than open the interpreter in ImageJ?
You can write a Jython script with a special header that uses the ImageJ launcher to execute, ensuring all needed libraries are on the classpath:
#!/bin/sh ''''exec "$(dirname "$0")"/ImageJ.sh --jython "$0" "[email protected]" # (call again with fiji)'''
But this hack only works on POSIX-compatible platforms (i.e., in the case of Windows you would need CYGWIN).
Fiji includes several example scripts like this―a short and sweet one is screenshot.py.
Note that Jython cannot call Python libraries that are backed by native code (e.g., scipy and numpy). But there is an experimental CPython script language, which uses the javabridge. It is still immature, and not distributed with Fiji yet. But it allows to call native Python code, including libraries backed by C/C++, from ImageJ. The plan is to include this language in Fiji in the future. In the meantime, you can build it yourself and drop the JAR file into ImageJ's jars
folder. And of course, feedback is welcome.
If you develop a more turnkey "Python-centric" solution as you desire, it would be awesome to add a page to the ImageJ wiki about it!
回答2:
Depending on the size of the image, you could use the javabridge connector developed by the Cell Profiler group. It is however notoriously slow.
If you want to design your own binding to ImageJ, you can use jepp/jpype couple, but it will be a lot of work.
The easiest way of doing it would probably be to save your image from ImageJ to an external file and write a macro that would save image, start your custom python processing script, and then re-open the processed image.
回答3:
The imglib2-imglyb
project allows to access numpy arrays from Java with ImgLib2 and vice versa.
Some illustrating examples can be found on imglyb-examples
.