Call imagej from python

Hi there,

I am trying to concatenate the work between Fiji and Numpy. Hopefully, the analysis result can be generated automatically by OpenCV. In order to compete this mission, I have established an environment called pyimagej under conda. Then, I activated the environment and Jupyter notebook under Anaconda Powershell. Here is the result.


Following the error report, I installed ‘scyjava’ through pip in the same environment. The installation of ‘scyjava’ was successful by checking with conda list. But it still showed the same error.
Can anyone help me to resolve this problem?

Sincerely,
Peggy

Dear Peggy,

try installing the environment according to the description in this repo:

and then executing your code. It might help.

Cheers,
s/

1 Like

Just because you mentioned OpenCV, you can also use it by scripting within Fiji by activating the IJ-OpenCV update site and converting from the ImageJ ImagePlus (or ImageProcessor) to Mat objects.
See

Dear sstoma and Laurent,

Thank you for your answer. The installation of i2k make it passed the first line “import imagej”, but here comes another problem that image j can not be initialized. It reported that “Your image j installation dose not support IJ1. This function does not work.” I know i2k is quite new since this Dec 1st. Is there any document or material available now to help us integrating Fiji and Python together?

Hi @Peggy!

A couple of questions for you.

  1. Did you want to load ImageJ or Fiji (via pyimagej)? For the latest imagej use ij = imagej.init(), for the latest Fiji use ij = imagej.init('sc.fiji:fiji'). Note that this will take a good amount of time to initilize for the first time as its downloading the .JAR files in the background.

  2. Did you activate your conda env (if you used the environment.yml file in the i2k-2020-pyimagej repo it’ll be named i2k-2020-pyimagej.

  3. Did you interrupt the initialization?

I’ve seen this error before and its usually caused by interrupting the intialial startup. Can you try to run this again and give it a little bit of time to run? This can take 3-5 minutes sometimes. After that it should start up quick once it has all the files it needs.

Alternatively you can point pyimagej to your local copy of imagej.

Hi Edward,
I found there are many demo notebook files in the created environment. In the ‘introduction’ section, the reproducible of each initiation method was noted. To consider the stability of the compile work , I decided to stick with the specific version of Fiji and the error was fixed. Thank you for your help.

All Best,
Peggy