imagej / pyimagej

Use ImageJ from Python
https://pyimagej.readthedocs.io/
Other
467 stars 81 forks source link

Compare Imagej-python tools #76

Closed phisanti closed 4 years ago

phisanti commented 4 years ago

Hi,

I write very frequently scripts for Imagej in python using the Jython interpreter but starting to consider using directly python. For that I am considering these options:

From the pure scripting approach, is there any significant differences among those? I mainly want to gain auto-completion - I tried installing this and this plugins without success, so I think using directly Python can help me with basic support.

ctrueden commented 4 years ago

@phisanti The first two options you list, imglyb and pyimagej, are really the same thing: PyImageJ is a convenience library that wraps all of ImageJ to Python, built on top of imglyb and scyjava (and therefore jgo and pyjnius).

The third option you list, the ImageJ Tutorial notebooks, use the BeakerX Groovy kernel, which is a JVM-based kernel—so not Python. There is one notebook in that collection, 1-Using-ImageJ/6-ImageJ-with-Python-Kernel.ipynb, which uses the Python kernel using pyimagej.

So really for Python syntax, you have two main options:

  1. Jython Scripting, which uses the Jython implementation of Python to run code on the JVM.
  2. PyImageJ, which brings the power of ImageJ/Java to CPython directly.

Jython is limited to Python 2.7, and does not support Python modules that need native code, such as NumPy and SciPy. Whereas with PyImageJ, you can use the full power of Python (i.e. CPython) including such native-backed modules, as well as scikit-image, ITK, OpenCV and other Python-accessible image processing tools.

I try to explain this distinction on the ImageJ wiki here:

https://imagej.net/Python

But maybe it's not clear enough, or doesn't have enough detail? Please feel warmly invited to edit that page to improve the information there. The ImageJ documentation is a community effort!

Regarding auto-completion: your time and energy here would be very useful. The aforementioned page does not talk about autocompletion, but I know you can achieve (limited compared to Java, but still useful) autocompletion of Jython code in IDEs such as PyCharm and probably also Spyder or PyDev. But no one has made a screencast or wiki page about it, to my knowledge. Certainly you can also achieve a similar level of autocompletion with CPython in those tools. If you find a good guide, or make a guide, please feel welcome to link it from the appropriate place(s) on imagej.net.

Happy to answer any followup questions if anything is still unclear.

ctrueden commented 4 years ago

@phisanti In future, please disclose when you cross-post. This was posted also as imglib/imglyb#11; see other responses there.

phisanti commented 4 years ago

Sorry for the cross-post and thanks for the clarification. It seems I should go for pyimagej and that should load everything I need.

Kind regards, Santi

ctrueden commented 4 years ago

@phisanti One gotcha with pyimagej at the moment is the need to downgrade imglyb to version 0.3.5, and pyjnius to 1.2.0. Sorry about that; I'm working on a new release of pyimagej that will tidy up the dependencies. Also: be sure to use conda—it's a lot easier to set up than with plain pip, due to the non-Python dependencies of Java and Maven.

Happy to help answer any questions or issues you have with PyImageJ.

A third possibility for Java/Python integration I didn't mention before, but which I now mention for completeness: GraalVM is a new polyglot VM from Oracle that has support for several languages, including experimental support for Python 3.7+. Among other major benefits, this system enables Just-In-Time compilation of code across multiple languages in the same runtime! Unfortunately, the Python support is not yet far enough along to run all the PyData goodies including NumPy, SciPy, scikit-image, scikit-learn, et al. But hopefully someday they'll get there! 🤞

imagejan commented 4 years ago

Also note that pyjnius is very close to a 1.3.0 release that will fix the bugs with 1.2.1. So it might be worth waiting just a couple more days to avoid a lot of hassle during installation.