var bgthreshold = 500; // threshold value for background macro "simple ratio single plane [q]" { t = getTitleStripExtension(); rename(t); while (nSlices > 2) { setSlice(nSlices); run("Delete Slice", "delete=channel"); } run("Split Channels"); donor = "C1-" + t; acceptor = "C2-" + t; selectWindow(donor); run("Cyan"); run("Median...", "radius=1"); changeValuesToNaN(100); selectWindow(acceptor); run("Yellow"); run("Median...", "radius=1"); changeValuesToNaN(400); imageCalculator("Divide create 32-bit", donor, acceptor); makeFavoriteAIFpseudocolorLUT(); } /* Simple ratioing macro for two channel images from Zeiss 880. Written for a cyan-yellow biosensor with excitation at 440 nm and emissions split below 500 nm above 500 nm. 16 bit images thresholded at 500 to remove background. */ macro "simple ratio stack" { t = getTitleStripExtension(); rename(t); run("Split Channels"); donor = "C1-" + t; acceptor = "C2-" + t; selectWindow(donor); run("Cyan"); run("Median...", "radius=1 stack"); changeValuesToNaN(500); selectWindow(acceptor); run("Yellow"); run("Median...", "radius=1 stack"); changeValuesToNaN(200); // for higher contrast ratio, subtract 499 and 199, based on #s above for thresholding, before the Divide next step imageCalculator("Divide create 32-bit stack", donor, acceptor); makeFavoriteAIFpseudocolorLUT(); } macro "Change Values to NaN" { changeValuesToNaN(bgthreshold); } //=========================================================================== function changeValuesToNaN(lowerbound) { // as implemented, does not work on multichannel hyperstacks for individual channels run("32-bit"); for (i=1; i<=nSlices(); i++){ setSlice(i); changeValues(0,lowerbound,NaN); } } //=========================================== macro "Recolor with ratio LUT [F6]"{ requires ('1.38f'); makeFavoriteAIFpseudocolorLUT(); } //=========================================== function makeFavoriteAIFpseudocolorLUT(){ red = newArray(0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,7,11,15,19,23,27,31,35,39,43,47,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,131,135,139,143,147,151,155,159,163,167,171,175,179,183,187,191,195,199,203,207,211,215,219,223,227,231,235,239,243,247,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255); green = newArray(0,1,2,3,4,5,6,7,8,9,10,9,9,8,8,7,7,6,6,5,5,5,4,4,3,3,2,2,1,1,0,0,0,7,15,23,31,39,47,55,63,71,79,87,95,103,111,119,127,135,143,151,159,167,175,183,191,199,207,215,223,231,239,247,255,247,239,231,223,215,207,199,191,183,175,167,159,151,143,135,128,129,131,132,134,135,137,139,140,142,143,145,147,148,150,151,153,154,156,158,159,161,162,164,166,167,169,170,172,174,175,177,178,180,181,183,185,186,188,189,191,193,194,196,197,199,201,202,204,205,207,208,210,212,213,215,216,218,220,221,223,224,226,228,229,231,232,234,235,237,239,240,242,243,245,247,248,250,251,253,255,251,247,243,239,235,231,227,223,219,215,211,207,203,199,195,191,187,183,179,175,171,167,163,159,155,151,147,143,139,135,131,127,123,119,115,111,107,103,99,95,91,87,83,79,75,71,67,63,59,55,51,47,43,39,35,31,27,23,19,15,11,7,3,0,8,16,24,32,41,49,57,65,74,82,90,98,106,115,123,131,139,148,156,164,172,180,189,197,205,213,222,230,238,246,254); blue = newArray(0,7,15,23,31,39,47,55,63,71,79,87,95,103,111,119,127,135,143,151,159,167,175,183,191,199,207,215,223,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,247,243,239,235,231,227,223,219,215,211,207,203,199,195,191,187,183,179,175,171,167,163,159,155,151,147,143,139,135,131,128,126,124,122,120,118,116,114,112,110,108,106,104,102,100,98,96,94,92,90,88,86,84,82,80,78,76,74,72,70,68,66,64,62,60,58,56,54,52,50,48,46,44,42,40,38,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,16,24,32,41,49,57,65,74,82,90,98,106,115,123,131,139,148,156,164,172,180,189,197,205,213,222,230,238,246,254); setLut(red, green, blue); } //=================================== macro "Save ROI Manager [F7]" { if ( getInfo("window.type") != "Image" ) exit("Make sure running macro from image window."); dir = getDirectory("image"); // where to save results if (lengthOf(dir) < 1) exit("Make sure the image was opened from disk."); title = getTitleStripExtension(); newName =dir + title + ".zip"; // add command to select none in ROIManager to mae sure all saved? roiManager("Save", newName); roiManager("reset"); } // end Save ROI Manager [F7] /==================================== // 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