Redirect measurment in a macro

I am trying to use the redirect measurement command in a macro. I have an imaged named AVG and one named SNR.
I have read that this would only work with a special command using a different class (ij.plugin.filter.Analyzer).

  • How can I use this within a macro?

Example code:

selectWindow("AVG");
run("8-bit");
run("Auto Threshold", "method=Otsu white stack");
//auto threshold requires 8 or 16 bit.
//use the AVG projection to create a mask

run("Set Measurements...", "mean limit redirect=None decimal=1");  //clears any redirect 
ij.plugin.filter.Analyzer.setRedirectImage(SNR); //sets the redirect to SNR

Cheers,
Kai

Hi Kai, :smile:

you can redirect the measurements to another image using this macro code:

redirectImageTitle = "SNR";
run("Set Measurements...", "mean limit redirect=" + redirectImageTitle + " decimal=1");

or using the static method setRedirectImage as you did, in Javascript:

importClass(ij.WindowManager);
importClass(ij.plugin.filter.Analyzer);

impSNR = WindowManager.getImage("SNR")
Analyzer.setRedirectImage(impSNR);

Note that when using the Limit to threshold option together with redirection, the threshold limit is applied on the target image, so run("Measure"); will measure the full ROI (if present) or the whole image, without applying a threshold limit if the target image wasn’t thresholded as well.

If you want to measure the masked objects of one image with the data of another image, use Analyze Particles (if you want to have single objects statistics) or use Edit > Selection > Create Selection on the mask image, then Edit > Selection > Restore Selection on the target image, and measure.

Cheers,
Jan

3 Likes

Thanks for the details, @imagejan. Now I finally know why the redirect never worked for me!

Cheers,
Niko

Thanks @imagejan!Works like a charm without redirect measurement:

selectWindow("AVG");
run("8-bit");
run("Auto Threshold", "method=Otsu white stack");
//identify beads (auto threshold requires 8 or 16 bit).

run("Create Selection");
//creates a selection from the thresholded image

selectWindow("SNR");
run("Restore Selection");
//restores selection on the SNR image

run("Set Measurements...", "mean decimal=2");
run("Measure");
//measure the mean intensity contained on the SNR image only within the selection
2 Likes