Macros for image analysis using Fiji/ImageJ

The list below contains a series of macros that have been developed by Paul Thomas, facility manager, for various users of the Bio Imaging platform. Please feel free to use, or modify, them in any way.

 

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.)

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).

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 = 10)

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

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

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

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

     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).

Comet Analysis

This 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. Individual cells are selected using the freehand tool and the ROIs are added to the ROI Manager before clicking OK to proceed to the next analysis. 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”.

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 an open, single-channel, multi-image, timelapse file in which 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 removing outlying pixels, Gaussian-blurring the image and subtracting background.

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 drag the associated zipped file onto the ImageJ toolbar, the ROI Manager will open containing all the ROIs, click on “Show All” and all the ROIs will appear on the image and indicate where the measurements were made during the analysis.

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 filters the individual frames using a Difference of Gaussians (DoG) approach (sigma values = 1 and 4), it then 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.

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.

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.

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” in 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.