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 |
> On Dec 10, 2016, at 5:39 PM, LP <[hidden email]> wrote:
> > 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. Use the Stack.getDimensions(w,h,c,z,t) function to get the number of time points and Stack.setPosition(c,z,t) to set the time point in a loop. The following example macro opens the Mitosis sample stack and inverts the second (green) channel of the third slice of each time point. run("Mitosis (26MB, 5D stack)"); Stack.getDimensions(width,height,channels,slices,frames); for (t=1; t<=frames; t++) { Stack.setPosition(2, 3, t); run("Invert", "slice"); } -wayne > _________________________ > 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 > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Loop-for-time-points-tp5017753.html > Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |