BoneJ Particle Analyzer Macro commands

bonej
segmentation
macro
Tags: #<Tag:0x00007fd540890f90> #<Tag:0x00007fd540890568> #<Tag:0x00007fd540890360>

#1

Hi all,
Simple question: I would like to use BoneJ’s Particle Analyzer in an IJ1 Macro script.The plugin doesn’t seem to be macro recordable, so how do I call it with user specified parameters from a script? Is there a python/javascript fix for this? I have no background in either of those, so I would be grateful for any guidance or links to manuals, etc for how to script in those languages.


#2

@mdoube I saw your replies to other BoneJ questions, would you happen to have a solution to this?


#3

Hello Feriel,

You can call the plugin with the macro command run("Particle Analyser"). Unfortunately this still requires user interaction, i.e. clicking the dialog buttons. The plugin doesn’t parse arguments from the run command.

A Python or Javascript can access all the public methods of a Java class, so this opens up more options. For example, you could call the method getParticles(), which returns the particle labelling and sizes. However many of the methods for further particle analysis such as Euler characteristic or thickness are not exposed in the Java API, and thus not accessible from a script.

Best Regards,
Richard


#4

Thanks for the quick reply @rimadoma ! My main need for Particle Analyzer is to use it as a 3D size filter that can check for connectivity of objects between slices, compute size, exclude small objects and retain large ones. This is just one step in a much longer script that batch processes and runs through multiple z-stacks, so it would be inconvenient for the user to interact with dialog boxes for stack after stack.
I don’t need Euler characteristic, etc, so getParticles() sounds right. I have never used Python or Javascript before, and am unsure how to proceed with calling the method from inside my IJ1 macro. Is there any way you could simplify that for me, or provide links to guides that could tell me how to construct the required lines of code?


#5

As far as I know there is no way to mix-and-match IJ1 macro language and Python/Javascript. However, have you considered the Analyze > Analyze Particles… plugin that comes with ImageJ? It is macro recordable, and supports size exclusion. For example, run("Analyze Particles...", "size=0-100 show=Nothing exclude"); labels particles whose area is 0 - 100 pixels, and excludes ones that intersect stack edges.


#6

It is important that the particles in our images be size filtered in a 3D manner, which Analyze Particles is unable to do. The Extended Particle Analyzer from the Biovoxxel Toolbox also works solely on 2D images. We have tried using the Find Connected Regions plugin, which worked exactly as we wanted, but it caused the count output lines in the Results table to be overwritten for stack after stack processed through the macro. Currently, our code uses the 3D Object Counter, however it can only perform a 6-connected size check, and we would like a 26-connected check instead.
It sounds like incorporating Particle Analyzer from BoneJ into our program might not work. Are there any similar recordable plugins that can filter in z?


#7

That sounds to me like you’d profit from running your analysis with KNIME. It fully supports 3D objects and feature measurements, and you can run ImageJ1 macro code for pre- and post-processing within a KNIME workflow if you like. Example workflows are available on their example server from within the application.

Well, there are some ways, but they have limitations:

  • There’s the eval("script", "...") and eval("python", "...") macro functions, see the documentation.
  • There’s also call() to call Java class methods directly, but this is limited to public static methods.

#8

It is here - I just recorded this with the default settings checked in the dialog box

run("Particle Analyser", "surface_area enclosed_volume moments euler thickness ellipsoids min=0.000 max=Infinity surface_resampling=2 show_particle show_surfaces show_centroids show_axes show_ellipsoids show_stack surface=Gradient split=0.000 volume_resampling=2 labelling=Mapped slices=2");

What are your versions of:

Java
ImageJ
BoneJ
OS

I have:
Java: 1.8.0_121 (64-bit)
ImageJ: 1.51f
BoneJ: 1.4.2-testing (though 1.4.2 and many versions earlier should behave just the same)
OS: Ubuntu 16.04 all up to date


#9

@mdoube, my versions are:
Java: 1.8.0_66 (64-bit)
ImageJ: 1.51g
OS: Windows 7 Enterprise
BoneJ downloaded straight from http://bonej.org/download/BoneJ_.jar in the last few weeks; I think it is 1.4.2

I tried using the code you recorded to run Particle Analyser, and got the following exception. No output windows I selected for opened up, and the progress bar in the Fiji status menu just wouldn’t fill all the way.

( Fiji Is Just) ImageJ 2.0.0-rc-59/1.51g; Java 1.8.0_66 [64-bit]; Windows 7 6.1; 78MB of 3006MB (2%)
     
    java.lang.ClassCastException: org.scijava.vecmath.Point3f cannot be cast to javax.vecmath.Point3f
    	at org.doube.bonej.ParticleCounter.getSurfacePoints(ParticleCounter.java:984)
    	at org.doube.bonej.ParticleCounter.run(ParticleCounter.java:253)
    	at ij.IJ.runUserPlugIn(IJ.java:217)
    	at ij.IJ.runPlugIn(IJ.java:181)
    	at ij.Executer.runCommand(Executer.java:137)
    	at ij.Executer.run(Executer.java:63)
    	at java.lang.Thread.run(Thread.java:745)

#10

This is a setup issue. The short answer is that BoneJ doesn’t play well with fully updated Fiji and Java 8 on Win/Mac, which is something @rimadoma is working hard to remedy.

In the meantime please use the setup suggestion mentioned in the other thread linked above.