/* Michael Cammer 20180421 Goal: To take folders with sequences of TIF files from the Evos microscope representing different channels of a timelapse experiment and merge them with customized contrast applied. The same contrast should applied throughout the entire sequence. In this version, one of the channels is a transmitted light image and the fluorescent channels are subtracted (or partially subtracted) to make the fluorescence more visible or not too bright in the result. When I began to plan the maco, I had to decide whether to load each channel name in an array or code each one separately. Because the processing may vary from channel to channel, decided on simply coding each channel separately. This is not a GUI user friendly implementation. The path has to be pasted in manually for each experiment. However, the "Scene1Interval02_GFP.tif" part in the body of the code should not have to be changed except for different channels. Also, numBeacons has to be entered maually and there is no error checking. Batch processing is not utilized in case the user wants to watch what is happening. */ // C:/Users/Michael/Documents/work/Yu M/20180411_Yu_M/Time Lapse '20180411routine' 2018-04-11 16.21.06/Beacon-1/Scene1Interval01.tif var numBeacons = 53; var path = "C:/Users/Michael/Documents/work/Yu M/20180411_Yu_M/Time Lapse '20180411routine' 2018-04-11 16.21.06/"; // This is the path where the beacons folders are var foldername = "Beacon-"; macro "process all stacks" { // openOneAndProcess(1); // exit(); for (beacon = 1; beacon <= numBeacons; beacon++) { openOneAndProcess(beacon); close(); } } // end macro process all stacks //================================================================ function openOneAndProcess(filenumber) { //RED run("Image Sequence...", "open=[" + path + foldername + filenumber + "\\Scene1Interval02_RFP.tif] file=RFP sort"); rename("RED"); call("ij.ImagePlus.setDefault16bitRange", 16); run("Enhance Contrast...", "saturated=0 normalize process_all use"); run("Duplicate...", "title=subred duplicate"); run("Multiply...", "value=0.2 stack"); //GREEN run("Image Sequence...", "open=[" + path + foldername + filenumber + "\\Scene1Interval02_GFP.tif] file=GFP sort"); rename("GREEN"); call("ij.ImagePlus.setDefault16bitRange", 16); run("Enhance Contrast...", "saturated=0 normalize process_all use"); //TRANS run("Image Sequence...", "open=[" + path + foldername + filenumber + "\\Scene1Interval02_TRANS.tif] file=TRANS sort"); rename("TRANS"); floatStack(); realmin = 999999999; realmax = -99999999; for (i = 1; i <= nSlices; i++) { setSlice(i); getRawStatistics(nPixels, meani, min, max, stdi, histogram); if (max > realmax) realmax = max; if (min < realmin) realmin = min; } // getting min and max of stack setMinAndMax(realmin, realmax); run("16-bit"); selectImage("TRANS"); // not necessary for the math but nice to see imageCalculator("Subtract stack", "TRANS","subred"); imageCalculator("Subtract stack", "TRANS", "GREEN"); selectImage("subred"); close(); //cleanup run("Merge Channels...", "c1=[RED] c2=[GREEN] c4=[TRANS] create ignore"); run("RGB Color", "slices"); //filename = path + "Beacon " + IJ.pad(filenumber,3) +" RGBmerged"; filename = path + "Beacon-" + filenumber +" RGBmerged"; saveAs("Tiff", filename); } //================================================================ // See http://microscopynotes.com/imagej/float/ for explanation. // originally by Kenton Arkill [underwaterginge@GMAIL.COM] // Floating means that each image has the same mean pixel value and the same standard deviation. // I find it really useful as it means the same threshold can often be used on all the images. Here is my macro, // it floats the stack to the values of the first slice (so make sure it is a good image): // function floatStack() { run("32-bit"); setSlice(1); getRawStatistics(nPixels, meanref, min, max, stdref, histogram); for (i = 1; i <= nSlices; i++) { setSlice(i); getRawStatistics(nPixels, meani, min, max, stdi, histogram); run("Subtract...", "value="+meani+" slice"); run("Divide...", "value="+stdi+" slice"); run("Multiply...", "value="+stdref+" slice"); run("Add...", "value="+stdref+" slice"); } run("Enhance Contrast", "saturated=0.00"); setSlice(1); } //================================================= // Use this function to strip any number of extensions // off images. // Returns the title without the extension. //================================================= function getTitleStripExtension() { t = getTitle(); extensions = newArray(".tif", ".tiff", ".lif", ".lsm", ".czi", ".nd2", ".ND2"); for(i=0; i