// Michael Cammer; Michael Dustin laboratory at Skirball at NYU Medical Dec 2011 // These macros were written specifically for Catarina Sacristan's multi-field timelapse experiments // on the Nikon TIRF microscope run by Elements software with files saved in .nd2 format. // The files are imported using LOCI BioFormats importer with all series selected and channels split. var number_of_radii = 2500; // number of pixels on perimeter of circle to be sampled. var clipsize = 150; // edge size of the box for clipping cells for montage var snipwindow = -1; var projectiondepth = 16; // default depth for projection of variable depth var tab = " \t"; // Should be updated each time macros are edited function checkCurrentVersion(){ requires('1.51e'); } //=========================================================================== macro "Change Values (works on stacks)"{ for (i=1; i<=nSlices(); i++){ setSlice(i); changeValues(4,99999,0); } } //=========================================================================== // This macro takes all open stacks and projects them. Depending on the filename, in this case // "C=#", the projection method may be different. The projection command automatically names // the new windows with the type of projection followed by the original filename. //=========================================================================== macro "Project all open stacks" { projectAllOpenStacks(); } // "Project all open stacks" function projectAllOpenStacks(){ n = nImages(); for (i=1; i<=n; i++) { selectImage(i); t = getTitleStripExtension(); if ( endsWith(getTitle(), "C=2") ) run("Z Project...", "start=1 stop="+nSlices+" projection=[Min Intensity]"); else run("Z Project...", "start=1 stop="+nSlices+" projection=[Max Intensity]"); rename(t+"_proj"); } // for i } // end projectAllOpenStacks() //=============================================================================== // Extracts the nth slice from a timelapse or Z stack. //=============================================================================== macro "Extract nth slices from stacks"{ extract_all_nth_timepoints(2); } function extract_all_nth_timepoints(extract) { // extract is an integer between 1 and nSlices n = nImages(); for (i=1; i<=n; i++) { selectImage(i); t = getTitleStripExtension(); setSlice(extract); title = "M" + extract + "_" + getTitle; run("Duplicate...", "title="+title); rename(t+"_s" + extract); } // for i } macro "=========================="{} //============================================================== // This is for when you already have color images. //macro "box location" { // getCursorLoc(x, y, z, mousestate); // makeRectangle(x-(boxsize/2),y-(boxsize/2), boxsize, boxsize); //} macro "Make snipping box" { makeRectangle(10,10, clipsize, clipsize); } //============================================================== macro "snip out the box [F5]" { roiManager("Add"); run("Duplicate...", "title=[snip]"); } //============================================================================= // calls function clipCellAndPopOnStack(original, clipstack); // macro "clip all ROIs in Roi Manager, center, rotate, and put in stack for montage [F4]" { original = getImageID; t = getTitle; bits = bitDepth(); if (bits == 24) bitstring="RGB"; else bitstring = ""+bits+"-bit"; clipsize = getNumber("Enter side of square box in pixels: ", clipsize); setPasteMode("Copy"); setBatchMode(true); newImage("snippedstack "+ t, bitstring+" Black", clipsize, clipsize, 1); clipstack = getImageID; for (i=0; iOptions>Colors... //4. Run this macro. // macro 'draw ROI on range of slices in stack'{ checkCurrentVersion(); image_to_process = getImageID(); Dialog.create("draw on slices..."); Dialog.addNumber("first slice to draw on", 1); Dialog.addNumber("last slice to draw on", nSlices()); Dialog.show(); first = Dialog.getNumber(); last = Dialog.getNumber(); if (last < first) { temp=first; first=last; last=temp; } if (first < 1) exit("first slice must be 1 or greater"); if (last > nSlices()) exit("last slice must be the stack size or smaller"); n = roiManager("count"); // get the last ROI in the manager selectImage(image_to_process); roiManager('select', n-1); for (i=first; i<=last; i++){ setSlice(i); run("Draw", "slice"); } // for loop run("Select None"); resetMinAndMax(); } // draw ROI on range of slices in stack //========================================================= macro "RGB merge adjacent slices into a new stack"{ //checkCurrentVersion(); setPasteMode("Copy"); original = getImageID(); selectImage(original); slices = nSlices()-2; for (i=1;i<=slices;i++) { selectImage(original); run("Set Slice...", "slice="+i); run("Select All"); run("Duplicate...", "title=[A]"); selectImage(original); run("Set Slice...", "slice="+(i+1)); run("Select All"); run("Duplicate...", "title=[B]"); selectImage(original); run("Set Slice...", "slice="+(i+2)); run("Select All"); run("Duplicate...", "title=[C]"); run("RGB Merge...", "red=[A] green=[B] blue=[C]"); if (i == 1) { newrgb = getImageID(); } else { run("Select All"); run("Copy"); close(); selectImage(newrgb); run("Add Slice"); run("Paste"); } } //for i selectImage(original); run("Set Slice...", "slice="+nSlices); run("Delete Slice"); run("Set Slice...", "slice="+1); run("Delete Slice"); run("Brightness/Contrast..."); selectImage(newrgb); run("Select None"); exit(); } //RGB merge adjacent slices into a new stack //================================================================== /* This macro is for making a movie of a stack that loops, especially useful for animated GIFs of 3D projections that rock back and forth. Downside: doubles the size of the stack. */ macro "Loop stack" { t = getTitle(); run("Duplicate...", "title=xyztemp duplicate"); run("Reverse"); run("Concatenate...", " title="+t+"_3D image1=["+t+"] image2=[xyztemp] image3=[-- None --]"); } macro "make test stack for Projections of variable width" { size = 25; slices = 50; width = 256; newImage("Untitled", "8-bit black", width, width, slices); setColor(255, 255, 255); for (i=1; i