Macros for image analysis using Fiji/ImageJ

 

The list below contains a series of macros that I have developed for various users over the last few years. Please feel free to use, or modify, them in any way you want. To load the macros into Fiji/ImageJ either:

A. Go to the Plugins menu, choose Macros → Run… , and navigate to the macro of choice (Note: some of the macros may require that an image already be open before running).

B. Open the macro by going to Plugins → Macros  Edit , and copy all of the text, then using the File menu of the Editor open “StartupMacros.fiji.ijm” (found in fiji.app\macros\), and paste the text of the new macro into the StartupMacros file. Restart Fiji and the new macro will appear in the Plugins  Macros menu every time you start Fiji. (Note: If you like, you can enter:  macro "-" {}  between individual macros, or groups of macros, to create a line between macros in the menu, and make the appearance cleaner.)

 

1. Spot Analysis: This is a basic macro to measure various properties of bright spots/objects in single-channel, fluorescence images.

     a. Open image, then run the macro. You will be asked to enter a location (folder) into which the macro will save the results of the analysis. You will also be asked to enter the pixel size (in microns) so that measurements are scaled appropriately.

     b. The first step is to perform a background subtraction, make sure “Light background” is UNchecked and set the rolling-ball radius to the desired setting (smaller values = more background subtraction) – check “Preview” to adjust before clicking OK.

     c. The next step is to create a binary image that will be used as a mask to analyse the original image. Either choose an algorithm from the drop-down menu (e.g., Otsu – good for small, roundish objects; Li – good for large, elongated structures), or manually adjust the sliders to remove background (or very bright spots) before clicking “Apply”, then OK to proceed.

     d. The next step is to choose the measurements you want to make. After choosing, be sure to select “Redirect to: Image0” and click OK. Then click OK again to proceed.

     e. You can then choose to analyse one or more ROIs, or the whole image. If you want to analyse the whole image enter Ctrl A, then click OK. When the ROI Manager opens click “Add(t)” and OK. If you want to analyse various ROIs, draw an ROI on the image (the macro defaults to freehand, but you can switch to rectangle or circle on the toolbar), then click OK and add to the ROI Manager. If you want to analyse multiple ROIs, just keep drawing and adding (click on “Show All” at the bottom to view all ROIs). After drawing all ROIs click on OK to proceed.

     f. At this point you will be able set filtering parameters to discriminate the objects you are interested in from noise or other unwanted spots. Filtering can be done based on size (enter lower and upper limits as appropriate) and/or Circularity (perfect circle = 1). Make sure to choose "Show: Outlines” from the drop-down menu and check “Display Results”.

     g. After each ROI is analysed you will be prompted to click OK to proceed.

     h. When the analysis is complete you will find two files for each ROI in the Results folder – a text file with the measurements (can be opened in Excel) and an image file (jpeg) showing the objects that have been measured (numbers correspond to the numbers in the text file).

 

2. Batch Spot Analysis: This is a macro to measure the size (sq. microns), and min, max and mean brightness of bright spots/objects in several single-channel, fluorescence images. You will need to put all the images to be analysed in a single folder (with no sub-folders). The macro will analyse the whole image (no ROIs selectable), and will apply all the same settings to each image. So, you will have to have determined these settings before running the macro. It is advisable to run the Spot Analysis macro on a few sample images to determine the values of these parameters before running the batch analysis.

Required parameters:

     i. Rolling-ball radius for background subtraction (Default = 5)

     ii. Minimum threshold value for binary (Default = 0)

     iii. Maximum threshold value for binary (Default = 255)

     iv. Minimum object size in sq. microns (Default = 0.1)

     v. Maximum object size in sq. microns (Default = 1000)

     vi. Lower Circularity limit must be >0.00 (Default 0.00)

     vii. Upper Circularity limit must be <1.00 (Default 1.00)

     viii. Pixel size in microns (Default = 0.1)

Run the macro, you will be prompted to enter the parameters listed above, and then asked to select both a folder to save the results to and a folder containing the images to be analysed. Once you’ve selected the location of the images to be analysed the macro will automatically load and analyse all the images in the folder (make sure there are no sub-folders, or any non-image files in the folder). When the analysis is complete you will find two files for each image in the Results folder – a text file with the measurements (can be opened in Excel) and an image file (jpeg) showing the objects that have been measured (numbers correspond to the numbers in the text file).

 

3. Comet AnalysisThis is essentially a combination of the Spot Analysis and the Batch Spot Analysis macros allowing semi-automated analysis of multiple ROIs in multiple images that are stored in a single folder. It also automatically thresholds the images using the Otsu algorithm. Remember, you need to draw and add all ROIs on the images before clicking OK to proceed to the next analysis – you will also have to delete the ROIs in the ROI Manager after analysing each image. The macro was developed using images obtained with a 63x/1.4NA objective, and so is optimized for such images.

     The results file contains the mean brightness of the comets, their length (Feret’s dia. in microns), and the circularity (0-1), as well as other “shape descriptors”.

 

4. Spot Comparison Analysis: This macro is a development of the Spot Analysis macro for semi-automated analysis of three ROIs in fluorescence images. It was designed to compare 2 channels (GFP-expressing and mCherry-expressing cells) of a multi-channel file in 3 different ROIs in each image. There are two versions, one for 3-channel files in which the first channel is a transmitted-light image that is discarded, the second version is for simple 2-channel files. Because three different ROIs are to be compared, the user needs to input 3 separate folder locations for the results of the 3 individual ROIs. The macro simply measures the area of the fluorescent objects in each ROI.

 

5.  Muscle fibre Analysis: This macro was developed to measure the diameter of muscle fibres in cross-sectional slices through pieces of muscle imaged with a 20x objective (potentially, it could also be used for fat cells in adipose tissue). There are three variants of the macro: i) for single-channel, grey-scale images, ii) for single-channel, RGB images, and iii) for two-channel, grey-scale images from which the second (DAPI) channel is discarded.

a. Open the image and run the macro. You will be prompted to enter the pixel size (in microns), and then to choose a location for the Results file (*.txt).

b. The macro subtracts background, removes bright outliers and then applies a Gaussian blur. The image is automatically thresholded and converted to binary.

c. The macro carries out the measurements and saves both an outline map of the analysed image and a Results file containing the data: area, perimeter and Feret’s measurements of each object/fibre.

d. Some of the analysed objects are blood vessels rather than muscle fibres; therefore, the original image, the outline map and the Results table remain open at the end of the analysis. The map can be compared with the original image and unwanted objects deleted from the Results before the file is saved (overwriting the original analysis). Alternatively, all the windows can be closed and the editing done later.

 

6. Tubulin Acetylation Analysis: This macro was written to compare the amount of acetylated tubulin to total tubulin in cultured cells. The comparison is made both semi-quantitatively (by area stained) and visually (an overlay of the two staining patterns is created). This is a batch process requiring that all the images to be analysed are present in a single directory; you will also have to create five other empty folders for various files used in the macro, and for saving the outputs (see below). There are two versions, one for 3-channel files in which the third channel is a DAPI image that is discarded, the second version is for simple 2-channel files. The first macro (3-channel) assumes that the “total” tubulin staining is in Channel 1 and that the “acetylated” tubulin staining is in Channel 2. The second macro (2-channel) assumes that the “total” tubulin staining is in Channel 2 and that the “acetylated” tubulin staining is in Channel 1.

Before the analysis starts you will be prompted to enter the following:

i. Rolling-ball radius for background subtraction (Default = 50)

     ii. Minimum object size in sq. microns (Default = 0.12)

     iii. Maximum object size in sq. microns (Default = 15000)

     iv. Pixel size in microns (Default = 0.1)

     v. Location for Channel 1 results

     vi. Location for Channel 1 threshold images

     vii. Location for Channel 2 results

viii. Location for Channel 2 threshold images

ix. Location for overlay images

x. Location of data files

Once you’ve selected the location of the images to be analysed the macro will automatically load and analyse all the images in the folder (make sure there are no sub-folders, or any non-image files in any of the required folders). It will create an overlay image for each of the files (black background, total tubulin in white and acetylated tubulin in green), placed in the “overlay” folder. The macro will also store a summary of the area of all the objects measured in each Channel of each image in the appropriate output folder.

 

7. F/F0 ratioing: This macro was developed for normalization of fluorescence between cells in semi-quantitative measurements of cytosolic [Ca2+] using the dye fluo4. It was developed for analysis of time-lapse recordings made with a 40x/1.3NA objective on a confocal microscope using a large pin-hole (optical slice ~5 microns). The macro requires that at least 10 frames are captured before addition of agonists (the first 10 frames are averaged to form the baseline – F0 – that is used for normalization). The macro also makes use of the “Time Series Analyzer V3” plug-in, so make sure this plug-in is installed before using the macro.

a. Open the time series, then run the macro. You will be asked to enter a location (folder) into which the macro will write the results.

b. The macro will “smooth” the image by Gaussian-blurring the image (sigma = 2.00).

c. Then the macro duplicates the first 10 frames and averages the frames to create a single image = F0. All the images in the time series are then divided by F0.

d. The F0 image is also used to create a “mask” that is used to supress spuriously high or low pixels in the background of the ratioed images.

e. As a result you will be presented with a smoothed, masked image on which you will be prompted to draw ROIs. Draw around each of the cells you wish to analyse and add the ROIs to the ROI Manager (click on “Show All” at the bottom to view all ROIs). After drawing all ROIs click on OK to proceed.

f. The “Time Series Analyzer V3” will load and you will be prompted to click on “Get Average”. Clicking this button gives rise to two windows: i) containing the ratio measurements of each cell/ROI in each frame of the time series (“Time Trace(s)”), and ii) a graph of the average response of all of the cells over time (“Time Trace Average”).

g. Click OK to proceed and the “Time Trace(s)” file will be saved in the designated results folder along with a multi-image, 32-bit tiff containing the analysed time-lapse (i.e., smooth, masked, and ratioed), and a jpeg of the “Time Trace Average” graph.

h. The “Time Series Analyzer V3” will load again, and again you will be prompted to click on “Get Average”. In this case the same ROIs are applied to the fluorescence, rather than the ratioed, images. The analyser will create another “Time Trace(s)” file and a second “Time Trace Average”.

i. Click OK to proceed and three more files will be generated and saved.

j. In addition, a zipped folder will be created containing the ROIs.

k. In total there will be 6 files and a zipped folder generated: 2 text files containing the variation in fluorescence intensity over time in each ROI/cell and the changes in ratio over time; 2 multi-image tiffs containing either the smoothed, masked fluorescence data or the equivalent ratio data, and 2 jpegs showing the average response of all the ROIs/cells over time, either fluorescence intensity or F/F0 ratio. The zipped folder can be extracted to reveal the ROI files. If you open one of the time series tiffs and then one of the ROIs, the ROI will be applied to the image. You can then open the ROI Manager (Analyze -> Tools ->) and add this ROI (“Add [t]”), you can then proceed to do the same for all the ROIs, and if you select “Show All”, you will be able to see where the measurements were made during the analysis.

 

8. Running sum: This macro was developed to map the elongation of growing microtubules in single cells expressing Fluorescent-Protein-tagged plus-end binding proteins; e.g., GFP-CLIP-170. It requires an image sequence in a folder with no other files or sub-folders. When you start the macro it will ask for a folder location for the resulting summed images. It will next ask for the location of the folder containing the original image sequence. Essentially, the macro saves frame 1 in the results folder, then adds together frame 1 and frame 2 and saves the result as frame 2 in the results folder, then adds frame 3 to the sum of frames 1 & 2 and saves the result as frame 3 in the results folder, then adds frame 4 to the sum of frames 1, 2 & 3, and saves the result as frame 4, etc, etc. The result is an image sequence that reveals the growth of the microtubules from the movement of individual FP-labelled comets.

NOTE: This macro gives the best results if the original comet images are filtered using a Difference of Gaussians (DoG) approach (typically images blurred with a sigma value of 4 are subtracted from images blurred with a sigma value of 1).

 

9. Time-differential analysis: This macro was developed to visualize the exocytosis of large, dense-core granules in secretory cells; in particular, zymogen granules in pancreatic acinar cells (see Campos-Toimil et al. [2000], J. Physiol., 528, pp. 317-326). It requires an image sequence in a folder with no other files or sub-folders. When you start the macro it will ask for a folder location for the resulting differential images. It will next ask for the location of the folder containing the original image sequence. Basically, the macro subtracts the second frame from the first, the third from the second, the fourth from the third, etc., etc. The result is an image sequence of grey, almost featureless images, but with granule-sized dark or bright spots where exocytosis has occurred.

 

10. Gel-band measurement: This is a simple macro designed to measure the density of bands in gels or Westerns. It requires an image of the gel/blot with dark bands on a light background. After opening the gel/blot image and running the macro, it will ask for a folder location for the results of the analysis. The macro will attempt to segment the image based on the density of the bands and you will be asked to manually threshold the image. After thresholding the macro will “fill holes” and “watershed” the binary image, then save the results (“integrated densities”) in a text file in the results folder along with a jpeg showing the measured ROIs overlaid on the original gel/blot image.