Binary mask macro command does not work

Hi All,

I hope someone can help me with this issue.

I’m creating a macro for my image segmentation & analysis. I’m doing so by recording all the actions and then adjusting the macro for all the images.

I got stuck at the point of making a binary mask. I copied the command from the macro recorder to my macro script but whenever I run the macro, I get a different result for the binary mask.

Can anyone tell me how to solve the issue?

This is the mask I manually get:

This is the mask I get with the same command in the macro script:

This is the line of the macro for creating a binary mask:
run(“Make Binary”, “method=Intermodes background=Default black”);

Appreciate your help!
Cheers!

Talia

Hi
@tal
Test these two small macros, one after the other.

setAutoThreshold("Default");
//setThreshold(0, 91);
run("Convert to Mask");
-------------------------------------
setAutoThreshold("Default dark");
//setThreshold(92, 255);
run("Convert to Mask");
-----------------------------------

Hi @Mathew,

Thanks for your input!

I tried to run the two macros and if I try them alone (no previous commands), the binary mask works.
However, if I run the previous part of the script before running these commands, the mask does not work anymore.

It’s my first time making a macro so perhaps you know why the binary mask command does not work within the script? Here it is:

macro "Calculate Volume" {
   input = getDirectory("Choose an input directory");
   output = getDirectory("Choose an output directory");
   list = getFileList(input);
   for (i=0; i<list.length; i++){
   	if (endsWith(list[i], ".tiff")){
   		open(input + list[i]);
   		filename = getTitle();
   		run("Properties...", "channels=1 slices=96 frames=1 unit=um pixel_width=0.200 pixel_height=0.200 voxel_depth=0.400");
   		setSlice(48);
   		run("Window/Level...");
   		resetMinAndMax();
   		setAutoThreshold("Default");
   		//setThreshold(0, 91);
   		run("Convert to Mask");
   		setAutoThreshold("Default dark");
   		//setThreshold(92, 255);
   		run("Convert to Mask");```

@tal
Thresholding allows you to define what you want to measure.
What you put in red with the thresholding will become white.

setAutoThreshold("Default");
//setThreshold(0, 91);
run("Convert to Mask");

or (excusive) [It’s one or the other]

   		setAutoThreshold("Default dark");
   		//setThreshold(92, 255);
   		run("Convert to Mask");```

@Mathew

I think I understand what you mean but I don’t know how to solve my issue.
How do I make the command of making a mask work in the same way in the macro as when I do it manually?

1.Open the recorder
2. Make a threshold on this image (so that black becomes red) [and Apply]
3. Close the image
4. Open the image again
5. Copy and paste the macro of the recorder into macro then run

Ok I think I figured it out! It seems to work now.

Thanks again @Mathew!

1 Like