Automated sholl analysis headless

Good morning,

I hope you’re keep well :slight_smile:

I’m trying to use pyimagej to run the following script which works fine for Sholl analysis 4.0.1. However, I’m unable to use for v4.0.2. see lines commented out. Could you provide me some details on how I could do this in headless mode?

importClass(Packages.ij.IJ)
importClass(Packages.ij.gui.PointRoi)


imp = IJ.openImage("/home/ryan/Documents/GitHub/temp/temp.tif");
IJ.run(imp, "Convert to Mask", "");
imp.setRoi(new PointRoi(512,512,"small yellow hybrid"));
imp.show();

// v4.0.2
//IJ.run(imp, "Sholl Analysis (From Image)...", "startradius=0.0 stepsize=0.0 endradius=512.0 hemishellchoice=[None. Use full shells] previewshells=false nspans=5.0 nspansintchoice=Mean primarybrancheschoice=[Use no. specified below:] primarybranches=1.0 polynomialchoice=[Use degree specified below:] polynomialdegree=2.0 normalizationmethoddescription=[Automatically choose] normalizerdescription=Default plotoutputdescription=[Linear plot] tableoutputdescription=[Detailed table] annotationsdescription=[ROIs (points and 2D shells)] lutchoice=mpl-viridis.lut luttable=net.imglib2.display.ColorTable8@1d99d123 save=true savedir=/home/ryan/Documents/GitHub/temp analysisaction=[Analyze image]");

// v4.0.1
IJ.run(imp, "Sholl Analysis...", "starting=10 ending=512 radius_step=0 #_samples=5 integration=Mean enclosing=1 #_primary=0 infer fit linear polynomial=[Best fitting degree] most normalizer=Area create overlay save directory=/home/ryan/Documents/GitHub/autoballs/scripts/temp");
IJ.run("Close All", "");

I then pass this macro as followed

args = {}
ij.py.run_script('js', script, args)

Furthermore, it would be ideal if I could pass the numpy array directly to the macro as I’m currently writing it out 'temp.tif'.

I look forward to hearing back from you :slight_smile:

All the best,
Ryan

Wow! Awesome. python calling JavaScript calling Java! Hooray for Scijava multi-language support!!

@rg314, I really have no idea why it stopped working. However, your problems would go away if you script SNT directly. You will have way more control over things. And you can do it straight from python!

In the script editor, have a look at the script in Templates→Neuroanatomy→Sholl Extract Profile from image (You can also find it on GitHub). It details how to perform a typical analysis from an image. To run it using pyimagej (rather than Jython, from within Fiji), you need to modify the import statements. I.e.:

What in Jython is:

from sc.fiji.snt.analysis.sholl import Profile, ShollUtils
from sc.fiji.snt.analysis.sholl.parsers import ImageParser2D, ImageParser3D

In ‘proper’ Python becomes:

from scyjava import jimport
Profile = jimport('sc.fiji.snt.analysis.sholl.Profile')
ShollUtils = jimport('sc.fiji.snt.analysis.sholl.ShollUtils')
ImageParser2D = jimport('sc.fiji.snt.analysis.sholl.parsers.ImageParser2D')
ImageParser3D = jimport('sc.fiji.snt.analysis.sholl.parsers.ImageParser3D')

Together with the remaing template scripts (e.g., the one on Extensive Sholl Statistics), you should be able perform your analysis with ease.

The collection of SNT notebooks has more details on how to script SNT from pyimagej. The Sholl API is at javadoc.scijava.org.

1 Like

Beautiful @tferr it worked nicely :smiley: thanks a lot for the help and take care!