Problems creating macros

Hi! I want to share a problema with you. Maybe there is someone that has more experience doing macros with Image J and could help me or just give me some advices.

I’m working with fluorescent microscopy images that come from a time-lapse. What I want to do is create ROIs by stabling a threshold. Once I have created the mask, I overlap it in the image stack in order to measure the fluorescent inside this ROIs. I want to do this with so many videos so the macro will be so so useful for me.

WHAT I DO:
Try to create the macro. Plugins >> macros >> record. The recorder windows opens and I make the clicks and I see how the commands are recording. Then I save: create >> File >> save as…
Then I try to run de macro as: Plugins >> macros >> run

WHAT HAPPENS:
When I run the macro it doesn’t work well. It doesn’t select the same ROIs.

I have revised the recorded commands but I don’t know what is the problem. It seems all it’s already but the last step it’s not working well.

I don’t know what could be the problem or the solution. Maybe I need a plugin that I haven’t got yet.

Thanks in advance.:slight_smile:

1 Like

Hello @Anna.Q and welcome to the ImageJ forum!

It would really help if you could post here both the macro you used and the image on which you run it so we can help you detecting possible errors.

Cheers!

Thanks @iarganda for your answer!

As you suggest I share some screenshoots of the masks and the same masks after running the macro.


And this is the macro:

run("8-bit");
setAutoThreshold("Huang dark");
//run("Threshold...");
//setThreshold(5, 255);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Dilate");
run("Fill Holes");
run("Analyze Particles...", "size=1000-1000000 show=Masks clear add in_situ");

Thanks! :slight_smile:

Can you post the original image? Did you choose manually the threshold value to binarize your image?

1 Like

@iarganda I share the original image that matches with the second mask image. And about the threshold yes I select it manually, I share also a screenshoot with the chosen values

Original image

Selected threshold

I select the values manually and then I press apply.

So that’s the answer why the results differ. The manual adjustment of the threshold is recorded, but commented out by default in the recorder, because you usually do not want to apply an absolute threshold but one robustly determined by an algorithm:

setAutoThreshold("Huang dark");
//run("Threshold...");
//setThreshold(5, 255);

To get consistent results, just remove the first two lines and un-comment the setThreshold(5, 255); command:

setThreshold(5, 255);

or better, try to select an algorithm that works well for your image without manual adjustment. (In my trials, the Triangle and Percentile methods give thresholds between 5 and 9 for your image.)

7 Likes

Thanks Jan :slight_smile: your suggestion is so helpful, I’m going to try removing that two lines you say. And if doesn’t work I will try to select a predetermined algorithm.

1 Like

Thank you very very much it works writting just setThreshold(5, 255); !!! :slight_smile: :slight_smile: :slight_smile: :slight_smile:

2 Likes

Hi @imagejan @iarganda I have another problem with the 2nd part of the macro. I want that the ROIS I have created overlapped on a stack of images and then get the fluorescent intensity of all the images.
I have a .lif file with all the 3 channels together ( BF, green, red). I want that the macro subtract first the red channel, apply the ROIS, multymeasure. Then open the green channel and apply the same.

The original macro (only for the red channel):

run("Make Substack...", "channels=2 frames=1-300");
selectWindow("Experiment DMSO 05122016.lif - Pos004_S001");
run("Make Substack...", "channels=1 frames=1-300");
selectWindow("Experiment DMSO 05122016.lif - Pos004_S001-1");
roiManager("Show None");
roiManager("Show All");
roiManager("Show All with labels");
roiManager("Multi Measure");

Second part, green channel:

selectWindow("Experiment DMSO 05122016.lif - Pos004_S001");
selectWindow("Experiment DMSO 05122016.lif - Pos004_S001-2");
run("Synchronize Windows");
roiManager("Show All");
roiManager("Multi Measure");

The idea is creating a macro that would be able to assign different variables to the different windows that create. I found this command “getTitle”, with that I can assign the active window to a variable, name=getTitle, but I don’t know how to assign the other ones nor how to tell ImageJ to change the active window. Maybe some of you know how adapt the original macro for having a universal one that I can use with all my time-lapse images.

I think the final script would be like the following but i can’t figure out how:

I select my initial stack

//Asign the initial stack to the variable Wind1
run("Make Substack...", "channels=2 frames=1-300");
//Asign the new stack to the variable Wind2
selectWindow("Wind1");
run("Make Substack...", "channels=1 frames=1-300");
//Asign the new stack to the variable Wind3
selectWindow("Wind2");
roiManager("Show None");
roiManager("Show All");
roiManager("Show All with labels");
roiManager("Multi Measure");
selectWindow("Wind1");
selectWindow("Wind3");
run("Synchronize Windows");
roiManager("Show All");
roiManager("Multi Measure");

Thanks :slight_smile: