How I could create an universal macro?

Hi I want to create an universal macro and I don’t know how. 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 . 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 in advance :slight_smile:

Hi @Anna.Q,

I think the getList("image.titles") will help you.

Try the macro below, it will print out a list of the titles of all the open images, then you can select them and do with them as you please.

list = getList("image.titles")
for( i = 0; i < list.length; i++ ) print( list[i] );

selectWindow( list[0] )

Will that help?
John

1 Like

@bogovicj Thanks for suggesting that. Finally I tried the next macro I share and it works!!

name=getTitle;
run("Make Substack...", "channels=2 frames=1-300");
name2=getTitle;
selectWindow(name);
run("Make Substack...", "channels=1 frames=1-300");
name3=getTitle;
//parte2
selectWindow(name2);
roiManager("Show None");
roiManager("Show All");
roiManager("Show All with labels");
roiManager("Multi Measure");
//parte3
selectWindow(name3);
run("Synchronize Windows");
roiManager("Show All");
roiManager("Multi Measure");

Thanks all! :blush:

3 Likes