ImageJ Macros

ImageJ image processing or measurement tasks can be packaged within macro text files to speed and automate analysis tasks. To use macro files, open them in ImageJ. They can be launched via the Macros --> Run Macro menu that appears at the top of the macro text window (in ImageJ). Some macros use keyboard keys to launch routines. Some prompt you to input source data and some require the data to be open already and act on the current (active) window. The comments in the first few macro lines typically describe what you need and what it does.

NIH examples are found at this link:
http://rsb.info.nih.gov/ij/macros/

Macro functions are described here:
http://rsb.info.nih.gov/ij/developer/macro/functions.html

General macro language syntax and examples are found here:
http://rsb.info.nih.gov/ij/developer/macro/macros.html



Filters developed by Vytas Bindokas at the University of Chicago

Hybrid 2D filters.class

Hybrid 3D filters.class

KalmanStack_Filter.class



Annotated bits of code to use when writing your own macro (for Macro Workshop participants and others)

These are NOT FULL MACROS but but chunks of code that perform certain operations. These can be copied and integrated into macros with or without modifications. Anything on the righthand side of a // is annotation, not necessary for the code but an explaination of what each step does.

Batch process a folder (loop) and save resulting images back to original folder

Batch process a folder (loop) and save resulting images to a NEW folder

Use ROIs created on one image to analyze another image (uses the ROI manager) - can draw ROIs or not depending on code



Full macros developed at the University of Chicago Light Microscopy Core Facility

Use your browser to save from the link or open the link, copy the lines to a plain text file, and save that as a .txt or .ijm file.

Note that these macros were developed for specific user projects and may not match your needs exactly. Some modification of the code may be necessary before the macro works for you.

3d counts and coloc2.txt Macro to select two files for 3D counts and colocalization. Input is Slidebook multipage tiff files. Requires installation of 3D_object_counter and colocalization plugins.

3D counts and coloc ROI v3.txt Macro to select two files for 3D counts and colocalization. Input is input is Slidebook multipage tiff. Requires installation of 3D_object_counter and colocalization plugins. F5 re-launced the ROI selector, F6 runs the main counting routine, F7 mercilessly closes all open image windows. BE SURE TO SAVE COUNTS RESULTS BEFORE ReRUNNING. Delete old ROI and add new if running many times. July 2006, Univ. of Chicago Light Microscopy Core, Vytas Bindokas.

3D count nuclei.txt Macro to count Dapi nuclei in confocal Z stack (16 bit). It reduces the image to the object centers then counts those by means of the 3D object counter plugin (required), and that takes care of merging overlapped objects. By Vytas Bindokas, Univ. of Chicago, April 2008.

3D count nuclei v2.txt . Updated 3D nuclei counter macro for newer ImageJ code. Features/changes this uses distance maps plus XY and XZ watershed steps to split objects "3D"; action is not perfect! Tuning steps are the rolling ball diam, the remove outlier diams; use smaller for low magnification input. by Vytas Bindokas, Univ of Chicago, June 2010

Stack of images showing 3D nuclei count.3-D nuclei (594).zip (17.9mb)

3D_FOCIcounts4ROIv1.txt Macro to perform 3D counts of nuclear foci. Input is a mutipage tiff. Requires installation of 3D_object_counter (newest version). F5 re-launced the ROI selector, F6 runs the main counting routine,F7 mercilessly closes all open image windows.BE SURE TO SAVE COUNTS RESULTS BEFORE ReRUNNNG. Delete old ROI and add new if running many times. Dec. 2006, Univ. of Chicago Light Microscopy Core, Vytas Bindokas.

3D count with watershed - macro to count DAPI nuclei in confocal Z stack (16bit). It reduces the image to the object centers then counts those by means of the 3D_object_counter plugin (required), and that takes care of merging overlapped objects http://rsb.info.nih.gov/ij/plugins/track/objects.html. Final output is a numbered red-green stack plus the report. Tuning steps would be the median radii and the expand diameters (decrease both for low magnification). Vytas Bindokas, Univ of Chicago, Apr 2008
Note: this uses distance maps plus XY and XZ watershed steps to split objects "3D"; action is not perfect !
Note 2: tuning steps are the rolling ball diam, the remove outlier diams; use smaller for low magnification input

4DanaglyphMaker v3.txt

4DMovieMakermv2.txt

4D MovieMaker v3rgb.txt

AB Batch measure GFPper nucleus from stk v4.txt Macro to add particle analyzer. Outlines to the ROI Manager and uses those ROI to perform within-object counts on other color channels. This counts green particles per nucleus defined by DAPI outlines. Macro asks for input STK file. ROI are numbered and overlaid on FITC image for documentation. Then save the RESULTS window 'save as' EXCEL works nicely. BE SURE TO CLOSE ALL IMAGE WINDOWS BEFORE reRunning. Modified 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, Univ. Chicago May '05. This is for 2-image stack, FITC then DAPI. University of Chicago Light Mircoscopy Core, Vytas Bindokas, May '06. Requires "1.35l"

AB measure GFPpernucleus from stk v2.txt This macro adds particle analyzer. Outlines to the ROI Manager and uses those ROI to perform within-object counts on other color channels. This counts green particles per nucleus defined by DAPI outlines macro asks for input STK file. ROI are numbered and overlaid on FITC images for documentation. Then save the RESULTS window data 'save as' EXCEL works nicely. BE SURE TO CLOSE ALL IMAGE WINDOWS BEFORE ReRUNNING modified 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, University of Chicago 2005 .This is for a 2-image stack, FITC then Dapi order. Requires "1.34k"

align hyperstack to clicked v2 - macro to Center+Register hyperstack to a point you click on in 1st slice. Click on next slice to advance. Aligns Ch, Z per time point to clicked. V.Bindokas, University of Chicago, APR 2013

Area measure from full color image - Macro for measuring area of brown from a full color histology image. This macro has two parts, one for batch process white balance correction and one for batch process measurements. To use, install both macros at the same time by choosing Macros --> Install Macros. White balance by Vytas Bindokas, Measurements by by Christine Labno, UChicago, April 2013

autophagosome / cell counter and area measure - This macro takes unput in single images. Must be installed and then called with the function buttons in order to work. There are three parts - F5 analyzes total cell area based on background in the autophagosome image, F6 counts autophagosomes and F7 counts cells based on DAPI nuclear counterstain. University of Chicago, Christine Labno, 2012

band maker macro - very simple macro to create a band (thickness is adjustable) based on a user-drawn polygon. Measures both the polygon and polygon after band. University of Chicago, Christine Labno, Fall 2012. To see a macro where this is used, see the JACoP band measure macro below.

BATCHconvert16bit to 8bit.txt This macro opens a directory of tiff images and resaves each as 8-bit. Univ. of Chicago, Vytas Bindokas, Jul'06. Requires ("1.35l").

BATCHconvert8bit to16bit.txt This macro opens a directory of tiff images and resaves each as 16-bit. Univ. of Chicago, Vytas Bindokas, Jul'06. Requires ("1.35l")

batchConvert16-to-8bitDIR.txt - Converts a folder full of 16-bit grayscale .tif files to 8-bit grasyscale .tif files and re-saves automatically. Can be used as an add-in to another macro.

BATCHcount dapi+green from 2xobjective DSUexports.txt For data from DSU microscope and 2x objective ONLY. This macro splits out DAPI channel, adds particle analyzer outlines and then counts the number opf green cells. Colored ROI are numbered and overlaid on images for documentation . Then save the RESULTS window data 'save as' EXCEL works nicely. Modified 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, Univ. of Chicago, May '05. This is for the RGB input images in a source direcory (selectable within macro run), Univ. Chicago, Vytas Bindokas, May'06.

BATCHcount dapi+green from 2Xobj DSUexportsGRNonly.txt For data from DSU microscope and 2x objective ONLY. This macro splits out DAPI channel, adds particle analyzer outlines and then counts the number of green cells. Colored ROI are numbered and overlaid on images for documentation. Then save the RESULTS window data 'save as' EXCEL works nicely. Modifed 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, University of Chicago, May 2005. This is for RGB input images in a source directory (selectable within macro run), Univ of Chicago, Vytas Bindokas, May'06

Batch file montage maker.txt This macro batch processes all STK files in a folder and any subfolders in that folder, as long as the stacks were captured in the order blue, red, green. The macro will make the 3 color RGB merge (not saved), then use the "RGB to Montage" plugin to create and save a 4 image montage.There is currently no additional image processing in this macro. Created by Christine Labno at the University of Chicago, April '07

Beginning foci macro v8 for Leica SP2 files.txt This macro is designed to measure and list the minimum distance from the edge of a foci spot to the nearest point on the surface of the nucleus in both x and xz. Takes z stacks from a Leica SP2 as input. Created by Christine Labno at the University of Chicago.

BestFocus.ijm - macro to to find best focus from xyzt multi-CH stack. V.Bindokas, University of Chicago, MAY 2013

BrdU_and_NeuN_ColocMacro.txt - Designed to count nuclei that are both BrdU (green) and NeuN (red) positive using thresholded masks and the Image Calculator AND feature. Uses the wait for user action to allow for custom thresholding of each image. Summary table can store results of several images. Created for E. Johnson of Cornell Univ. by C. Labno, Univ. of Chicago, March 2013, ImageJ 1.46p2

bugSpread_v1.txt Uses images with red bacteria and blue nuclei in RGB image as source. Finds a circular ROI that contains 75% of bug signal and counts nuclei in that ROI. Use this image as a demo image. By Vytas Bindokas, University of Chicago, June 2010

BuildRatio_From2stks.txt Macro to make ratio from stk input selection for numerator and demoninator -- showMessage("select numerator file").

ClosestDistanceMacro.ijm - macro to measure distance to closest neighbor. Input is meant to be ulimate points map with white on black IN BINARY MODE. EDM output is NOT binary by default! V.Bindokas, Univ. of Chicago, OCT 2012

color image cell count - This macro does a color threshold and cell count in a user-selected region (polygon tool) of an RGB color image. Open image to be analyzed, use Ctrl + R to start the macro and follow instructions on the screen. Univ of Chicago, Christine Labno, Jan. 2013. Created with ImageJ 1.46p2

count_3D_nuclei_vFIJI - macro to count DAPI nuclei in confocal Z stack (8or16bit) it reduces the image to the object centers then counts those by means of the 3D_object_counter plugin built into FIJI Final output is a numbered red-green stack plus the report tuning steps would be the median radii and the expand diameters (decr both for low magnification). Vytas Bindokas, Univ of Chicago, June 2010 updated for newer ImageJ code/features/changes reworked for FIJI version FEB 2013 this uses distance maps plus XY and XZ watershed steps to split objects "3D"; action is not perfect ! tuning steps are the rolling ball diam, the remove outlier diams; use smaller for low magnification input

count_3D_nuclei_vFIJI_2 - macro to count DAPI nuclei in confocal Z stack (8or16bit). It reduces the image to the object centers then counts those by means of the 3D_object_counter plugin built into FIJI. Final output is a numbered red-green stack plus the report. Tuning steps would be the median radii and the expand diameters (decr both for low magnification) Vytas Bindokas, Univ of Chicago, June 2010 updated for newer ImageJ code/features/changes reworked for FIJI version FEB 2013, and again after binanry black vs white function flip-flop MAR 2013 I really wish fiji and imageJ KEPT binary operations constant vs changing how it works!!! this uses distance maps plus XY and XZ watershed steps to split objects "3D"; action is not perfect ! tuning steps are the rolling ball diam, the remove outlier diams; use smaller for low magnification input

count FISH Particles from RGB 2.txt This macro adds particle analyzer. Outlines to the ROI Managerand uses those ROi to perform within-object counts on other color channels. This counts green particles per nucleus defined by DAPI outines. First open the RGB image (one can use individual files opened in order R G B, too; comment out RGB line below). ROi are numbered and overlaid on RGB image for documentation. Then copy/all + paste into spreadsheet or save the LOG (or RESULTS) window data. Modifed 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, Univ. of Chicago, April 2005 requires("1.33k").

dapi-golgi orientations macro Macro to draw line from nuclear centroid to golgi centroid. Expected input dapi and one other image, OPEN prior to running macro. Output prints angles and lengths in excel-friendly copy/paste format. V.Bindokas, Univ. of Chicago, FEB 2013

dapi tunel counter macro to count tunel positive cells based on dapi outlines. Tune the TNLthrsh value to pick up signal

deHAZE..txt Macro to perform MetaMorph-like haze reduction based on adjacent 3-D data; V. Bindokas; UofChicago, June'04.

epithelial cell area.txt This macro is for measuring the area of epithelial cells outlined with a fluorescent membrane dye. The cells are found automatically and then tracked by the ROI manager as they change shape over a time stack. Created by Christine Labno, University of Chicago, October 2011

FISH distance macro v1.txt This macro is designed to report the minimum distance of a FISH spot (center or edge) to the rim of the nucleus (as defined by DAPI) in a 2D image. Written by Christine Labno, University of Chicago 2012

flat fix v3.txt Macro to pseudo-flat-field correct images, taking grayscale stacks or var bit depths as input. Should be accuratefor intensity correction. By Vyts Bindokas, University of Chicago, April 2008.

flat fix v4.txt Macro to -pseudo-flat-field correct images, taking grayscale stacks or var bit depths as input should be accurate for intensity correction; stack uses a common shade image vers4 corrects the rescaling factors. by Vytas Bindokas, Univ. of Chicago, June 2008

flatten illum.txt Performs pseudo shading correction from blur=50.

foci_DoG_Macro.txt DoG feature extraction (edge for big objects); cleans up tiny structures. Difference of Gaussians calc; low blur selects size and noise level: hi blur corrects backgrounds etc. It will take anything for input. Created by Vytas Bindokas, Univ of Chicago, April 2007

graybalancetoROI.txt This macro white balances RGB to a selected region (equal R,G,B =gray). Draw a region prior to running the macro. Vytas Bindokas; Oct 2006, Univ. of Chicago.

hyperstack maker macro - Takes a regular z stack of images and makes it into a hyperstack, then creates an RGB image from the hyperstack. Adjust line 6 to fit your input data.

islet counter v2.txt Macro to count number of islets from a 2D pancreas slice image. The image can be either fluorescent (hit F5) or histology (hit F6). Created April 2010 by Christine Labno at the University of Chicago Light Microscopy Core Facility

JACoP band measure macro - Macro to analyze colocalization of green and red labeled proteins in just the outer perimeter of a tetrahymena. Outer perimeter deteced using thresholded red channel. Input needed = hyperstack with image order green, red. Names of images are not passed to JACoP but are instead printed into the log window before the analysis. Created for Joe Briguglio, Aaron Turkewitz lab, by Christine Labno, UChicago, April 2013

low signal eraser - uses getPixel since MUCH faster vs ROI marchings. Input 16bit 2D raw grayscale stack, noisy in = noisy out. For morphology and mask generation ONLY TOTALLY NON-QUANTITAIVE OUTPUT !!!!!!!!! V.Bindokas, Univ. of Chicago, NOV 2012
related but slightly different- signal stretcher macro - uses getPixel since MUCH faster vs ROI marchings. Input 16bit 2D raw grayscale stack, noisy in = noisy out. Note: for morphology and mask generation ONLY!!! TOTALLY NON-QUANTITAIVE OUTPUT !!!!!!!!! V.Bindokas, Univ. of Chicago, NOV 2012

manual measure in two images.txt Macro "manual measure in two images [F8]" {open the fitc and red stacks, rename them as "fitc" and "red", respectively. Draw an ROI on the fitc zymosan. Then hit F8 key to log both measurement results. Move the ROI and repeat F8 as needed; then copy results table. Vytas Bindokas, Apr 15'05.

mask background macro - works on a stack, finds an object by threshold, then enlarges a 2 pixel area around that obejct and wipes out background beyond that point.

measure particle details per nucleus This macro adds particle analyzer outlines to the ROI Managerand uses those ROi to perform within-object counts on other color channels. This counts green particles per nucleus defined by DAPI outines. Macro asks for input STK file. ROI are numbered and overlaid on fitc image for documentation.Then save the RESULTS window data 'save as' EXCEL works nicely. BE SURE TO CLOSE ALL IMAGE WINDOWS BEFORE ReRUNNING .Modifed 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, Univ. of Chicago, May 2005. This is for 2-image stack, FITC then dapi order, 12-bit, requires("1.34k");

MDC and lysosome (spot) counter macro v3.txt Designed to start with a two channel stack where image 1 is MDC+ particles and image 2 is lysotracker positive particles. Counts and records particles from each image. Created by Christine Labno, University of Chicago, 2011.

Measure vessels macro - macro to measure blood vessel density and characteristics. Input expects dark vessels on light background. Macro overlays vessel segments and brach types as hyperstack layers requires G.Landini's 'binary connectivity' plugin contained in: http://www.dentistry.bham.ac.uk/landinig/software/morphology.zip Outputs area fraction, # line segments, # bifurcations, # trifurcations. V.Bindokas, PhD, Unvi of Chicago, July 2012

Montage maker macro - takes a stack of images and creates a montage with the montage maker macro. This is similar to the macro shown in our ImageJ Basics class and Macro Writing workshops. Know your input and output desired and adjust accordingly!!

paintoutRGB2white.txt This tool whites out a color range based on point selection. RGB only! (obviously). Vytas Bindokas, University of Chicago, Dec. 2006.

pap Macro v1.txt Macro to measure PAP smears. Vytas Bindokas, Univ. of Chicago, Dec.,2006. inut is color image, converts to fluor-like image.

percent of nuclei that are green.txt The purpose of this macro is to determine the number of DAPI-stained nuclei in a given image that are also FITC positive. This macro uses images from the Leica SP2 taken with the 60x oil objective with no confocal zoom. Created by Christine Labno, Univ. of Chicago, June '07

perinuclear_measures_v2.txt A better version of the perinuclear_measures macro. Adds an outlines-as-overlays mode to the image output. As always, verify this works for your needs! Vytas Bindokas, Univ of Chicago MAR 2012
related - particle surround measures - macro to measure green channel brightness in area adjacent to red particles. blue, red, green order hyperstack expected as input; outputs overlaid score and map including ID numbers. Christine Labno modified from Vytas Bindokas, for T. Jordan of Randall lab, Univ of Chicago, April 2013

pH_ratioMacro".txt macro to calculate ratio of green/red per ROI from stack where slice1=green, 2=dic, 3=re.d Perform "install macros" under MACROS menu above, then Open stack (import image seq), draw background ROI, hit F12, Then F9 to process each ROI you draw; save log window results when done. ROImanager can show ROI via button; close manager and log before next runs. This uses separate thresholds on green and red extension of background subtraction macro originally by Michael Cammer 20030118. Mods by Vytas Bindokas, Univ. of Chicago, Nov.2006

pixFRET over time (loop) macro.txt - Designed to do compute the FRET ratio two fluorophores over a timelapse. Uses the pixFRET plugin and input is Leica .lif file but can be converted to accept any .tiff stack. Christine Labno, Univ. of Chicago, Oct 2012.

pseudo flatfield correction macro for DIC.txt (simple version) This macro is for pseudo-flatfield correction of DIC images. Created with ImageJ 1.45j10 by Christine Labno, University of Chicago, October 2011

renumberLEICAOKMacro.txt Macro to fix numbering scheme in Leica tif format/macro extracts "_tSEQ_" number and left-pads so files import right, good directory order. Sample name: voodoo_t97_z19_ch1.tif. Rename: voodoo_t00097_z19_ch1.tif. Requires this string format; quits, if it's wrong. Default padding to 5 places. July'06 Vytas Bindokas, Univ. of Chicago.

Sarayu's Macro5.txt Macro to measure DNA and GFP per cell (SLidebook zseries inputs needed by Vytas Bindokas, Univ. of Chicago, Aug 2006. must clear results table before rerunning!!!

spineCntMcro5.txt 3-D spine countiing macro for reflected light images of Golgi-stained neurons. Requires ImageJ plugins Gabrial Landini's binaryconnectivity and the 3D object counter(newest).This skeletonizes and finds branch points then counts them in 2D and 3D.Any spines exactly vertical will NOT be counted since the connectivity is only XY. But one would guess this is a rare case; skew spines should get counted with threshold set right.Vytas Bindokas, Dec 2006, Univ. of Chicago.

stack2Leica-tifnames2.txt Macro to save every slice using Leica named tiff format.

SynapseCounter_v5_withRestoreSelection.ijm - Determines number of green, red and colocalized synapes in an image. User inputs the folder for image saving and the thresholds for green and red images. Have your image open before running the macro, wants an RGB tif. Christine Labno, Univ. of Chicago, Fall 2012.

Track cells over time and shape change.txt This macro is for measuring the area of epithelial cells outlined with a fluorescent membrane dye. The cells are found automatically and then tracked by the ROI manager as they change shape and position over a time stack. Created by Christine Labno, University of Chicago, October 2011

unWMacro"".txt Macro to unwarp stack of tiffs, to correct for peristalic movement artifacts, etc. You need to press DONE button quickly in unwarp GUI to get it to run right. nS is the number of slices per volume, change before run. Run unwarp as accurate, very coarse, fine,0.1,0,0,3,.01 (set 1st pass). Requires download of B.I.G "unwarpJ" plugin (obviously). http://bigwww.epfl.ch/thevenaz/UnwarpJ/. This version for t-lapse, reset every nS to avoid over-wander.Macro by Vytas Bindokas, Univ. of Chicago, Sept 2006

Vesta's bugMacro v3.txt Macro to count red and green and colocalized objects in a two-slice tiff, assuming red is slice 1. F5 massages and counts red, green, and colocalized. F7 mercilessly closes all open image windows. Uses fixed threshold. Vytas Bindokas, University of Chicago Light Microscopy Core, July 2006

White balance images:This macro white balances RGB to a selected region (equal R,G,B =gray)( draw a region prior to running the macro). Vytas Bindokas; Oct 2006,Univ. of Chicago

YK count nuclear particles from stk v4.txt This macro adds particle analyzer. Outlines to the ROI Managerand uses those ROi to perform within-object counts on other color channels. This counts green particles per nucleus defined by DAPI outines. First open the RGB image (one can use individual files opened in order R G B, too; comment out RGB line below). ROi are numbered and overlaid on RGB image, and spots in white, for documentation. Then copy/all + paste into spreadsheet or save the LOG (or RESULTS) window data . BE SURE TO CLOSE ALL IMAGE WINDOWS BEFORE ReRUNNING since macro uses image numbers 1-3. Modifed 'RoiManagerAddParticles.txt' macro; balance by Vytas Bindokas, Univ. of Chicago, April 2005, requires("1.34k").