Python script example for 3D particle analysis

Tags: #<Tag:0x00007fd53e6100b0> #<Tag:0x00007fd53e60ff70> #<Tag:0x00007fd53e60fe08>


Hi guys,

has anyone a python script that is using the 3d toolbox for partice anaylsis. I found some macros etc. but I would really prefer to stick to python.

Thanks, Sebi


Hi @sebi06,

Do you mean the 3D-objects counter specifically, as indicated by the topic tag?

You can translate the macros to python if you prefer (as I do myself). As an example, a simple 3d objects counter run recorded by the macro recorder can be translated very easily:

IJ macro:

run("Fly Brain (1MB)");
run("3D Objects Counter", "threshold=62 slice=25 min.=10 max.=8000000 exclude_objects_on_edges objects surfaces centroids centres_of_masses statistics summary");

In p(j)ython:

from ij import IJ"Fly Brain (1MB)")"8-bit")"3D Objects Counter", "threshold=62 slice=25"
       + " min.=10 max.=8000000 exclude_objects_on_edges"
       + " objects surfaces centroids centres_of_masses statistics summary")

Edit: If you provide a more extensive macro that does what you want maybe we can help you make it work in Python, if you really need it to. The macro language is quite capable too!


Hi Sverre,

thanks a lot. I tried that one out and as you said it woks fine. Nevertheless I will also try to use MorphoLibJ and its API to achieve the same. It seems to me that I have more flexibilty there.


I didn’t find an API for the 3d-objects-counter but then again, everything is available from the macro calls :slight_smile:

Good luck and let us know if you get stuck! And there is some useful information on the jython scripting page if you didn’t spot it yet.


Hi @Sverre ,

I finally got my python script running using MorphoLibJ and its API. Just in case you are interested, you can find it here:

[MorpholibJ and labelToRGB inside python script]


Thanks for sharing :slight_smile: