Running an imagej script from python

I am currently trying to run a python script on a set of histogram data extracted from fiji through .csv files. The histogram data is generated using fiji’s inbuilt script writer and the analysis is performed using a python sript written by someone else. I want to move the fiji (jython) script to python and operate in there solely is there anyway of doing this?

Hi Sam,
Well you could use the python package pyimagej to run the jython script within python.
See pyimagej/Usage.md at master · imagej/pyimagej (github.com)
But that would require a bit of fiddling around.

Otherwise simply copy pasting the jython code in a python environment wont work.
You could try to rewrite the histogram calculation from jython to python using numpy or scikit image, but again that’s a bit of work.

Hi Laurent,

Thankyou for your response. Is there anyway to extract the greyscale values from an ROI using pyimageJ? I have rewritten the histogram script but I am really struggling to work out how to import the ROI values.

It is important that I can select the ROI in imagej.

I haven’t been using pyimagej so I dont know, you will have to explore the documentation and example notebooks.
Otherwise, in ImageJ you could click the “Measure” button from the RoiManager once you have annotated all ROIs first ticking the Bounding Rectangle option in the menu “Analyze > set Measurement” to recover a table with the Roi coordinates. Then you could save this table as csv and import it in python.