How to run "Erode" plugin in macro with specified options?

I have included “Erode” function to a macro. Later I have found that all “Binary” functions can be modified by options which are set up in Menu of Fiji. So the same line of a code: run(“Erode”), will result in different outcomes depending on what are actual setups on Usere’s machine. With other functions it is possible to define their options if they have any. I could’t find it for “Erode”. Could you help me?


You can just include Binary Options settings in your macro code… for example:

run("Options...", "iterations=1 count=1 black");

This will ensure all have the same functionality when running your macro code.

1 Like

Dear etarena,
Thank you very much for your response.
Unfortunately it does not work. The image is processed in the same way, no matter what I type in the code. The only thing that has any effect is changing the numbers in FIJI Menu.
Thanks anyway

I think @etarena is right but just one argument is missing (from the “do” combo box). Something like:

run("Options...", "iterations=2 count=2 do=Erode");

or similar should work.

If you use the makro rekorder and apply the options don’t forget to set the “do” combo box for your custom arguments, see:

1 Like

Actually I did in the other way around. Basically, I wanted to remove small dots (1-2 pixels) from a thresholded image. Someone suggested to use “Erode” function. But I have just found another suggestion, to use “Analyze particle” function which allows to remove objects smaller than a given value prior to analysis and creates such a “cleared” a mask. I use this mask to my further analysis. And most importantly a command
run(“Analyze Particles…”, “size=2-Infinity pixel show=Masks”)
works pretty well and image is processed according to values typed in the code.

Anyway, I am at starting point of my work with macros in ImageJ and I do appreciate all the suggestions.

1 Like

Hi. There is a morphological operation that does this without having to run the particle analyzer. It is called “opening by reconstruction” (or “Binary Filter Reconstruct” in the Morphology collection update site): removes regions that that disappear after n erosions, but without modifying anything else.

By the way, if you want to make the Erode (and many other) options permanent, it is a good idea to put the recorded lines mentioned above in the StartupMacros.txt file. When you share your code, you just share that file as well, and it gets loaded by default, guaranteeing that the macros work as you expected in other computers too.

Thank you gabriel. I will try both solutions.