ImageJ / Fiji

Our team promotes the use of the open platform ImageJ for bioimage processing and analysis. Thanks to 
ImageJ, and in particular the Fiji distribution, we develop custom solutions to process and analyze microscopy data, with mainly two goals in mind: Develop tools to accelerate and automate image analysis and data management,and develop analysis routines to extract quantitative data from the images.

Among the ImageJ macros we have developed, here are some example workflows addressing common bioimage analysis problems. 

                                            Note: All the macros have been tested under Fiji Life-line, 2014 June 2 version.


Automated Multicellular Tissue Analysis

Macro                Example image (180 K)

This macro is meant to segment the cells of a multicellular tissue. It is written for images showing highly contrasted and uniformly stained cell membranes (Fig. 1.1). The geometry of the cells and their organization is automatically extracted and exported to an ImageJ results table. This includes: Cell area, major, minor fitted ellipse radii + major axis orientation and number of neighbors of the cells. Manual correction of the automatic segmentation is supported (merge split cells, split merged cells). The analysis can be restricted to a user defined Region of Interest (Fig 1.2). To segment the cells of a movie you can use this macro, if you are interested in cell tracking you can have a look at this page.

Fig. 1.1 Drosophila embryo expressing mCherry-cadherin                                                 Fig. 1.2 Result of the segmentation
         spinning disk, maximum intensity projection                                                             
       (Image courtesy of Annalisa Letiza, IBMB-CSIC) 


1) Pre-filtering radius should be adapted to the image noise, typical values in the range 1 to 3 pixels.
2) The cell detection sensitivity can be set (values in range 0 to 255) or manually adjusted (-1).
3) The minimum area overlap between the dilated cell boundaries (1 pixel outside the initial boundary) and the surrounding neighbor cells. Can be used to discard neighbor cells only cornering a cell.
4) Manual correction (merge split cells, split merged cells), neighbor counting and plotting the cell area and number of neighbors distributions are optional.



Measurements for each cell, the row index corresponds to the labels in Fig 1.2.

FISH Signals detection in Human Spermatozoids

Macro     Example1 (1 MB)    Example2 (24.6 MB)

Aim and prerequisites

The macro segments and classifies human spermatozoids nuclei (DAPI) based on the number of FISH signals (spots) they contain. It reports the percentage of occurrences of user defined classes (combinations of spot multiplicity in the FISH channels) as well as the position (point selections) of the detected nuclei falling in these classes. The input image should be an hyperstack with 4 channels: DAPI (first channel) and three FISH channels. The images are typically obtained as a maximum intensity projection of few channels (confocal) or a single z slice acquisition (widefield). The macro requires this LUT to run (it should be copied to Fiji LUT folder).   

Fig. 2.1 The original image is an hyperstack with 4 channels (DAPI first) and 3 FISH channels. 
It is represented here as a color composite. 
(Image Courtesy of Anna Godo, Universitat Autònoma de Barcelona)


When launching the macro the number of nucleus classes can be defined in the first dialog box. The combination of FISH spots for each nucleus class is defined in the next dialog box. If a specific channel is un-ticked the spot count is ignored for this channel. In the lower part of the dialog box you will find:

Nuclei segmentation parameters:

1) Nucleus smooth: radius (pix) of the Laplacian of Gaussian filter used as a pre-filtering step.
2) Nucleus sensitivity: a negative value typically in the range [-0.5 to -0.1], the smaller the value the less sensitive the detection.
3) The next two values define the lower and upper bound for the nuclei area. These values are dimensionless multiplicative coefficients of the median area of all the particles detected in the image (isolated nuclei assumed in majority).
4) The nucleus minimum circularity.
5) The number of one pixel dilation step of the nucleus segmentation mask before counting the spots (to make sure close the edge spots are detected inside the nucleus).

Spots detection parameters:

1) Spot smoothing is the radius (pix) of the Laplacian of Gaussian pre-filter applied to each FISH channel.
2) Spot background radius should be set to at least two or three times the expected radius of the spots.
3) The last three channels set the spot detection sensitivity in each of the three FISH channels (8-bit scale).  


Fig. 2.2 The result image. The contours of the detected nuclei are color coded according to their spot content.
Only the nuclei checking the user selected combination of spots are selected (point selection).

The estimated median area (pixels) of the nuclei is reported in the log. Clusters of nuclei that could not be split are discarded. This helps avoiding to count spots in a nucleus they do not belong to. The frequency of the nuclei found in each of the user defined classes is also reported (relative to the total number of nuclei that were detected).

Protein MicroArray Analysis

Macro    Example image (1.8 MB)

Aim and prerequisites  

This macro performs measurements of average and standard deviation intensity inside wells of a protein microarray (the number of wells is limited to 250, the image should be cropped for larger arrays). The macro requires the "ImageJ plugins toolkit". To ensure compatibility with Fiji you should download the version 1.6.1. The installation instructions can be found here, it only consists in un-compressing the .jar file from the previous archive to Fiji plugins folder.

     Fig. 3.1 A fluorescence image from a protein microarray
contrast saturated (Image courtesy of Fulvio Santacatterina, CBMSO)


1)The number of wells per row
2) The number of wells per column
3) The default value can be used for the noise tolerance if the original image is 16-bit with correct exposition.
4) Background subtraction and manual adjustment of the noise tolerance (used to detect the well centers) are both optional.


The ROI labels correspond to the labels in Fig. 2.1.

Blood vessel segmentation and network analysis

Macro    Example1 (7 MB)    Example2 (13.5 MB)

Aim and prerequisites

This macro segments blood vessels in a 3D stack. It is suited for well contrasted images (low background) and works better if the width of the vessels of interest is reasonably uniform. The stack should be calibrated (micro-meter). The macro requires the ImageJ 3D suite that can be found here and this LUT (it should be copied to Fiji LUT folder). 

Fig. 4.1 This example image was obtained by lectin-rhodamine 
staining in mice and Macro SPIM acquisition (here 3D rendering representation)
(Image courtesy of Alexandre Calon, IRB Barcelona)


1) The first two parameters should both be set to the approximate expected radius of the blood vessels They control the closing of the tube (tube filling) and the filament pre-filter.

2) Vessel threshold: Sets the intensity sensitivity of the detection (the lower the more sensitive).

3) " Remove branched with end-points": Skeleton branches leading to an end-point can optionally be removed.

4) "Dilate Skeleton for viewing by (pixels)": Only used for visualization in the 3D viewer.

5) "Number of threads": Many filters are multi-threaded, for best performance adjust this value to the number of cores of your CPU(s) or twice this number if your architecture supports hyperthreading.

6) "Save intermediate steps": Save all the intermediate results (stacks) to disk.


The results consist of:

1) A label mask of connected components (Fig 4.2).
2) A labelled skeleton stack showing the skeleton, the branching and end-points (Fig 4.3).
3) A log holding some statistics on the blood vessel network (Fig 4.4) such as the average blood vessel cross-section area and diameter, the total length of the network, the number of branches and the overall vascularization density (volume fraction occupied by the blood vessels). 

                      Fig 4.2 Skeleton with end-points (white)                                           Fig 4.3 Connected components label mask 
                                  and branching points (yellow)                                                                                               

Fig 4.4 Statistics displayed in Fiji log window

Tissue analysis from histological sections

Macro        Raw Data (1 MB)   

Aim and prerequisites

This macro batch processes all the 2D images (tif and jpg files such as in figure 9.1) located in a user defined folder by calling Fiji Weka trainable segmentation to classify each pixel, and reports the areas of each class in a human readable results table. The classifier to be applied to each image should be previously trained on a representative image by an expert and exported to file (Save classifier) into the image folder to be processed. After launching the macro you will be asked to pick any image from the folder to process, all the images will then be processed. 


classifier: The classifier is expected to have the default name (classifier.model), unless changed in the string classifier of the macro preamble.

WekaVersionThe macro has only be tested with v2.1.0-SNAPSHOT of the Weka trainable segmentation plugin. It might also work with a different version but it should then be updated in the first line of the macro (call Weka trainable segmentation on any image and copy the exact name of the plugin window to the string WekaVersion).

SaveClassification: The results (label mask, results table) are automatically stored to the image folder if SaveClassification is set to true in the macro.


The results consist of:

1) A label mask (one gray level per class, figure 9.2) exported to the image folder as a ROI manager selection (zip file). It is easy to overlay it to the original images by drag and dropping this zip file to the Fiji bar and ticking/unticking "Show all" in the ROI manager window.

2) A results table (figure 9.3) reporting the name of all the images analysed and the fractional area of each class (on image per line).

Fig 9.1 Original image                                         Figure 9.2 Label mask 
(RGB image, Trichrome)                                     background (black), collagen (orange), muscle (cyan), nuclei (white)
(Image courtesy of Alexandre Calon, IRB Barcelona)

                                                    Fig 9.3 Results table reporting the fractional area of each class

Micro-tubule comets 2D tracking

Aim and prerequisites

This macro is meant to process spinning disk time-lapses (14-bit images). It segments the soma, reports its area (first frame only) and detect/count the micro-tubule comets appearing inside the soma across the time-lapse. It should work even if the fluorescence signal from the comets is weak (as in the sample image) but this might involve some parameters tweaking.


Manual ROI drawing (tick box): By default the macro is intending to automatically segment the cell for all time points. If this fails it is possible to use a user drawn segmentation mask (then fixed across time). This mask is used: 1) To restrict the comet detection 2) To report the cell area.

Approximate radius: Comet approximate radius in pixels.

Detection threshold: Intensity sensitivity level for comet detection. Set by default to 775, typically in the range 600-900 for 14-bit images.

Border retraction: Controls the number of pixels that the macro is using as retraction margin from the cell boundary. This setting is based on the observation that many cells show bright signal (autofluorescence) close to the borders that is not comet specific. You may reduce it to 2-3 pixels if the cell edges are clean, or set it to 5 pixels or more if the macro is counting false positives close to the cell boundary.

Min spot area: Minimum area of a comet (in pixel). Smaller comets particles are discarded.

Spot dilation: Dilation of the detected comets (in pixel). The dilation is used after comet detection to ensure an overlap between the same comet from frame to frame and avoid multiple counting of the same comet.


The results consist of:

1) A reference image showing the detected soma after border retraction and comets (Fig 10.2).
2) A log showing the image name, the soma area and the comet (spot) count (Fig 10.3).

Fig 10.1                               Fig 10.2
A time point of the           The same time point 
original time-lapse           with segmented soma 
                                              (after border retraction) 
                                              and segmented comets

Image courtesy of Carlos Sánchez, IRB Barcelona

Fig 10.3
The log showing the area of the segmented soma in first time frame
and the count of comets (spots) for the whole time-lapse


SPIM de-striper

Macro    Sample image (4 MB)

Aim / Results

This macro implements an image filter meant to mitigate close to parallel attenuation stripes, such as the ones typically observed in (fixed) light sheet microscopy. The filter is designed to cope with some stripe angular spread (e.g. due to light sheet refraction at the sample surface, see Fig 5.1), and it can process a 3D stack in one go (but the processing is performed slice by slice).



        Fig. 5.1 Original image (Zebrafish epibolia)                  Fig. 5.2 Filtered image with default settings
       (Image courtesy of Maria Marsal, IBMB - CSIC)


For stripe width similar to the sample image, setting "SubRad" and "OpenRad" to 40 and disabling sharpening (SharpenRad = 0) is a good starting point. Scale these values proportionally to the typical width of the stripes. Some guidelines to further adjust the parameters:

1) Thin stripes apparent in filtered image                     --> decrease OpenRad
2) Large, uniform, stripes apparent in filtered image    --> increase SubRad
3) Filtered image looks "blocky" and too smooth            --> increase OpenRad
4) Filtered image looks dirty and distorted                    --> decrease SubRad

SharpenRad / SharpenFeedback are the parameters of a post-processing high-pass filter meant to boost the high frequency part of the spectrum that might have been too attenuated by the main filter. Increase SharpenFeedback to sharpen more (practical range: 0 to 0.5), adjust SharpenRad to obtain the best results.

Tube un-winder

Macro   Example image (16.4 MB)


This macro can be used to un-wide a tubular structure and flatten its surface (like peeling of and flattening the skin of a banana). The macro can only process a single channel 3D stack but it is easy to process multiple channels by exporting and importing ROI manager selections. Technically the macro computes the radial average intensity projection inside a ring centered on the radial symmetry axis of the object. The final image is a radial mapping of the intensity (radial angle along X, axial length along Y).

Fig. 6.1 The original 3D stack (composite 3D rendering of the 3 channels)
(Image Courtesy of Nareg Djabrayan, IRB Barcelona)


The tube axis and contour are user drawn from three different views. The contours are saved to the ROI manager automatically. If the macro is launched with exactly 3 selections in the ROI manager it will use these contours automatically without asking the user to draw them (same transformation applied); it is hence easy to process multi-channel 3D stacks. The contours can also be saved from the ROI manager window to keep them as reference with the original data.


Fig. 6.2 Resulting un-winded image
The image has also been vertically shifted (circular shift) to show the best orientation
(Image Courtesy of Nareg Djabrayan, IRB Barcelona) 

Somata segmentation and time response analysis in acute rodent brain slices 

Macro     Example image (13.5 MB)


This macro automatically detects cell somata in acute rodent brain slices time-lapses after noise reduction and image registration (as required), it extracts fluorescence changes relative to baseline (dF/F) over time, and classifies cells as responsive versus non-responsive based on the presence or absence of significant fluorescence peaks in their time response.


Fig. 9.1 (1) Original time-lapse (filtered + maximum intensity projection), (2) somata detection, (3) normalized time traces extraction showing a responsive cell (top) and a non-responsive cell (bottom), (4) cell classification (responsive: red, non-responsive: yellow)
(Image courtesy of Hyojung Lee, IBEC)

Steps implemented and parameters (set in the macro code, not from a dialog box)

I)          Noise reduction of the OGB-1 fluorescence intensity image sequences by:

        1. Spatial filtering (Gaussian blur sigma: FltRad)

        2. Temporal averaging (optional; TmpGroup: 1 or 2 frames averaging were used for this study)

II)         Registration (image stabilization) if the sample suffers from spatial drift during the acquisition (set Register to true).

III)       Identification of cell somata as intensity regional maxima in the maximum intensity temporal projection of the filtered time-lapse. Users can finely adjust somata detection by:

        1. Adjusting noise tolerance (NoiseTol)

        2. Interactively editing the detected somata from the ROI Manager

IV)       Measurement of average intensity as a function of time inside fixed-radius circular regions (adjustable radius CellRad; typically 5-9 pixels for this study,) centered on detected maxima.

V)        Independent normalization of time traces by scaling them by their average over a selected number of initial time frames (BasalRange frames of the spatially filtered movie included).

VI)       Classification of the somata as responsive (red) or non-responsive (yellow) based on the presence/absence of significant peaks (typically 20%-30% increase respect to baseline, set by Alpha) in their normalized time trace. A cell is classified as positive if at least MinPeaks of minimum width MinWidth are detected.

VII)      Localization of burst maxima / width (default at half height, adjustable by PeakEdthFractionin the time traces.

VIII)    Exportation of all results as tabular files: raw time traces, estimated initial basal levels, and detected bursts. 

Note: For debugging purpose it is possible to sequentially plot all time traces and display detected peaks by setting PlotEach to true.

(Z,T) Hyperstack Stitcher

Macro    Example image (33 MB)
Aim / Results

This macro builds a stitched image from a muti-position 3D + time hyperstack. The XY positions of the montage should be coded as channels in the input  hyperstack. Channel ordering can be configured in the dialog box to adapt to Column/Row and Meander/Comb configurations: The images should appear in this order when browsing the hyperstack with the channel slider. Fine stitching is supported (requires sufficient overlap between the views). The XY displacements of each field of view for stitching are computed for a single reference (Z,T) slice (user configurable) and applied to all slices (Z and T).

Note: for OME file naming the hyperstack can easily be generated by importing the files and transforming the stack to an hyperstack with xyzct convention (provided the L and T fields of the OME files are equal) or xyztc convention if the L field is constant. In this case the Column/column comb configuration should be used regardless of the configuration of the scan acquisition. In case of different file naming (e.g. single index) another convention might be required.

Fig. 7.1 Example stitching for 2x2 XY positions
(Image courtesy of Jelena Urosevic, IRB)


1) The number of Y positions of the acquisition (number of rows) 
2) The number of X positions of the acquisition (number of columns)
3) The order in which the images appear when browsed from the hyperstack (channel slider)
4) The overlap between the images in both X and Y dimensions (coarse estimate)
5) A parameter used to control the tolerance of the stitiching
6) Tick "stitch" only if you want to perform a fine stitching of the images, if not the coarse overlap estimate is used to position the images.
7) The reference z slice to perform the fine stitching (same X/Y displacements are applied to all other slice).

(Z,T,C) Stitcher

Macro     Example Data set (19.6 MB)
Aim / Results

This macro can stitch a (Z,T,C) data set with virtually no limit on the number of Z slices and time frames. The input to the macro is a folder with the raw tiff images (one image per file) as typically exported by motorized microscopes. These files must all be stores in the same folder and the file naming should ideally comply to OME-TIFF. The macro is however quite flexible: Only --X, --Y and --Z fields with user defined number of digits are compulsory. --T, --C and --L fields with user defined number of digits are necessary for multiple time frames / channels data sets. A compatible data set is provided as a .zip archive. Before processing it unzip it to a given location.

The stitching is performed in a reference Z slice (and in a specific reference time frame and channel). The same displacements are applied to all the Z slices, time frames and channels. Before starting the batch processing a montage with the original images of the selected Z slice / time frame / channel is displayed together with the stitched image in this stack. If you are not satisfied with the result you can select another reference. The stitching is then performed time frame by time frame and slice by slice and the stitched images are exported to a single user defined output folder.  

The macro can also process a data set with multiple channels, the stitching is then
 computed once on a reference channel and then applied to the other channels.


1) The number of fields of view per column that you want to stitch (not necessarily the whole data set).
2) The number of fields of view per row that you want to stitch (not necessarily the whole data set).
3) The number of Z slice that you want to process (not necessarily the whole data set).
4) The number of time frames that you want to process (not necessarily the whole data set).
5) The overlap (%) between the images in both X and Y dimensions (coarse estimate)
6) A parameter used to control the tolerance of the stitiching: 0 (loose) to 1 (picky)
7) The image fusion mode you want to apply for the stitching
8) The common root name of the stitched image exported to the result folder

Special features

1) You can display the accumulated Z maximum intensity projection as progressing through the stack
2) In case you want to process another channel tick "Additional channel". You then have to input the L and C fields indexes of the new channel. The processing can be performed by launching the macro N times (for N channels). In case you want to batch process two channels in a row you have to tick "Launch additional channel on complete", select one of the two channels as reference and configure the other channel in the C/L fields.   

Additional parameters

If the first index of the column/row of the grid you want to stitch is not 0 you can enter the index.
If the first Z slice or time frame of the grid you want to stitch is not 0 you can enter the index.

File Naming
You can set the number of digits of the X,Y,Z,T and L fields.

Interactive Volume of Interest Extractor in Large 3D Stacks  

Macro     Example image (13.5 MB)

Aim and prerequisites

Fig. 8.1 The downscaled interactive intensity projection stack
(Image courtesy of Alexandre Calon, IRB Barcelona)

This macro allows to interact with a large, single channel, z-stack (possibly exceeding the main memory of the computer) and to extract a volume of interest by marking several reference points. The macro requires this plugin that should be copied to the "plugins" folder of FIJI. The macro is only compatible with 8-bit stacks.

The 3D stack should be opened first. When the macro is launched for the first time it computes the maximum intensity projection of the stack from multiple angles (rotation around Y axis). If the 3D stack is very large and does not fit into memory in should be opened as virtual stack.

Parameters and mode of operation

1) Step sets the angular step in degrees between the views computed in the maximum intensity projections stack
2) Max angle sets the maximum (last) angle to compute
3) Scale factor is a downscaling factor (along the 3 spatial dimensions). You should set this factor so that the downscaled stack occupies less than half the main memory available. Bear in mind that if the original stack does not have a voxel Z ratio equal to 1 the downscaled stack will be scaled so that this ratio is 1 (this typically induces a size increase). The estimated size of the downscaled stack is printed to screen, you can abort the macro by pressing escape if this size is too large.
4) Anaglyph can be ticked to generate a Red/Cyan maximum intensity projection anaglyph
5) In case the anaglyph is generated the angle step multiplier sets the offset between the views. It is always a multiple of the projection stack angular step.

It is then possible to interactively add reference points to the projection stack by holding "shift" and left clicking. The position of the point is "locked" in 3D by searching the position of the point from which the maximum intensity of the clicked pixel originates from. The 3D position of the reference points are reported to the log window (pixel unit in the original stack). If this does not work well for your image you can also try holding "alt" + left click, the Z position is then defined by the current angle of rotation.

The process of adding reference points can be stopped or the last reference point removed by pressing "space". At least 3 reference points should be defined, the smallest volume of interest containing all the reference points is then extracted (a new stack is created) and displayed in the 3D viewer.

Note: To extract several VOI from the same stack the maximum intensity projection stack and the depth projection stack can be saved to file and the macro launched again with the 3 stacks opened (original + projection stacks). The projections will then not be recomputed.  


Fig. 8.2 The extracted Volume of Interest
(3D rendering)