Login  Register

Loop for time points

Posted by LP on Dec 10, 2016; 10:39pm
URL: http://imagej.273.s1.nabble.com/Loop-for-time-points-tp5017753.html

Dear ImageJ community,

I wrote the following macro that basically uses the first channel to create a mask on the second channel and then clears everything that's out of the mask. It works fine on my Z-stacks.

However I have multiple time points and I don't know how to make the following macro go to the next time point once it did the first one.

So basically I'd like to add before my line 5 the equivalent of "for (s = 1; s < nSlices(); s++){ " but for time points.
_________________________
name = File.nameWithoutExtension();
setBatchMode(false);

                function (Splitchannel){
                        run("Split Channels");

                for (s = 1; s < nSlices(); s++){
               
                        selectWindow("C1-"+name + ".tif");
                        setAutoThreshold("Default dark");
                        run("Create Mask");
                        setOption("BlackBackground", false);
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Dilate");
                        run("Create Selection");
                        roiManager("Add");

                        selectWindow("C2-"+name + ".tif");
                        roiManager("Select", 0);
                        setBackgroundColor(0, 0, 0);
                        run("Clear Outside", "slice");
                        roiManager("Deselect");
                        roiManager("Delete");
                        selectWindow("mask");
                        close();

                        selectWindow("C2-"+name + ".tif");
                        run("Next Slice [>]");
                        selectWindow("C1-"+name + ".tif");
                        run("Next Slice [>]");
                }

run("Merge Channels...", "c1=[C1-"+name + ".tif] c2=[C2-"+name + ".tif] create");
Stack.setDisplayMode("color");
run("Save");
close();
__________________________

Any suggestion and help will be very appreciated.

Thank you very much for your help in advance,
LP