PLEASE: Beginner Help Needed: Writing Custom Thresholding Macro


I’m new to macro writing and would love it if someone could help me here. I’m currently using a macro to analyse the size & shape of mitochondria in cells from B&W fluorescence images - this macro required thresholding of the image to a binary image. Is there a way to set up a macro to auto-threshold the image within the confines of 25% of maximal intensity and maximal intensity?

If it is not possible to do this in a macro - is there any other way of doing this?

For reference, I am using imageJ 1.41 (due to the age of the macro i’m using) on a Mac.

Any help or advice would be greatly appreciated!


Dear @RJM,

welcome to the forum! :slight_smile:

The following macro will create a binarized version of the currently active image:

// Get maximum intensity value
getStatistics(dummy, dummy, dummy, max, dummy, dummy);

// Set threshold
setThreshold(0.25*max, max);

// Create binary image
run("Convert to Mask");

If you want to learn more about macro programming, you should take a look at



Thank you very much, Stefan! That works perfectly.

All the best!

1 Like