Counting fluorescently (or clearly defined brightfield) stained cells is a relatively easy process in Fiji. Information such as shape, area, intensity etc. can also be extracted on top of just a raw count number.
This example uses just a nuclear stain (like DAPI) to count the number of cells. A later chapter will show how to segment out individual whole cells and measure them.
This chapter will show how to carry out both 2D and 3D analysis. Note that 3D analysis is not super user friendly in Fiji and will require a reasonable amount of computer resources to carry out.
Before anything can be counted a binary image of it needs to be created.
Open Nuclei.tif from the Demo Images\Widefield\Segmentation folder
2. Create a duplicate of the nuclei image to work with
3. Threshold the image
4. Go to Process 🡪 Binary 🡪 Make Binary or press the Apply button in the threshold window
5. If you look at the resulting binary image you will notice that there are several nuclei that are fused together. If we were to count this image now these nuclei would be counted as one cell, not two.
6. These can be easily separated by going to Process 🡪 Binary 🡪 Watershed
NOTE The binary watershed function works fine on these images as they are basically round objects joined together. The watershed function essentially draws a dividing line between the two objects. If the objects are not rounded (e.g cells with large processes) the watershed function may give a strange result.
7. The result will be the majority of the joined nuclei being separated. Some will not be but this is better than nothing.
This binary image can now be used for further analysis
Go to Analyse 🡪 Analyse Particles…
2. In the Analyse Particles dialog leave Size and Circularity at their default values. Set Show: to Outlines and tick the boxes as below. Press OK.
This sets the module to count everything (except for objects touching the edge of the image), display a summary table of the results and show a result image of the outlines that were measured.
3. The results are shown in the table and as the outline image. The results show that there are 397 cells in the image, but if you look closely (for example in the top left corner) there are some things being counted that are too small to be a nuclei.
4. To filter out these results close the outline image and the summary table. Open the Analyse Particles module again but this time set the Size value to 50-Infinity. Press OK.
5. Now any objects smaller than 50 square pixels are not being counted and adding error to the result.
If you look at the outline results from the previous analysis you will notice that each out line has a unique number associated with it. This is because each object is measured individually and we can get other parameters out about it as well.
Close the outline image and the summary results table. Then go to Analyse 🡪 Set Measurements…
2. In this window the different measurements you want to make can be selected. For this example select the options as shown below and press OK.
3. Go to the Analyse Particles module again but this time also tick the Display Results checkbox and press OK.
4. You will now get an extra results table with detailed information about each of the cell objects in the image. This table can be saved as a text file or exported to excel for further analysis.
The values for Circ, AR, Round and Solidity describe the shape of the objects measured. For example a Circ value of 1.0 is a perfect circle.
5. If you look at the Mean column you will notice that all the objects have the same values, in this case 255 because we measured the binary image in which all objects were pure white. We can instead measure this intensity of the original nuclei image by using the binary image as a mask.
6. Close the outline mage and two results tables. Go back into Set Measurements… and set the Redirect to: value to the original nuclei image and press OK.
7. Re-run Analyse Particles on the binary image. Notice that there are now different Mean values for each object
8. To view a distribution of the data select the Results window and go to Results 🡪 Distribution…
9. In the Distribution dialog set the Parameter: to what you want to graph, in this example the mean intensity, leave the other settings as default and press OK.
10. The result is a histogram showing the distribution of the average intensities in the sample
If you press the List button you will get a list that can be saved to recreate the histogram in Excel.
Artificial intelligence approaches to image analysis are becoming more common and easier to use. Most AI pipelines are built in python and do not always have an easy to use GUI or simple commands. Some, however, have been adapted to be used in Fiji as a simple plugin. StarDist is one such plugin that allows easy, accurate and rapid identification of nuclei from both fluorescent and brightfield images. The built in models work well in the vast majority of cases but the option exists to train your own model to more specifically match your sample.
NOTE: Before proceeding make sure the StarDist and CSBDeep plugins have been added via the update sites. The plugin can be manually ran to analyse a single 2D slice. Using macro code it can be made to analyse both time and 3D data as well.
Open Nuclei.tif from Demo Images\Widefield\Segmentation
2. Go to Plugins 🡪 StarDist 🡪 StarDist 2D
3. The StarDist 2D configuration window has a range of parameters that can be adjusted to get optimal segmentation or to apply your own trained model.
To keep things simple to start with the only settings that need to be configured are
- Model – set to Versatile (fluorescent nuclei)
- Probability/Score Threshold – set to 0.70
- Overlap Threshold – set to 0.00
- Output Type – Both
4. Press OK and you should get a bunch of ROIs in the ROI manager and a coloured segmentation mask
If not all objects are being detected try dropping the probability threshold but that may lead to an increase in the number of false positive detections as it will detect some background as objects.
Generally there is never a need to change the Overlap Threshold above 0. For example, increasing the threshold to 0.3 results in some outlines overlapping that will result in double counting in some measurements.
There are two options for generating a binary mask from the StarDist results. Either works fine for manual analysis but for automated analysis through code the ROI method is easier to do.
Create a new blank image the size of the original image (in this case 696x512) by going to File 🡪 New 🡪 Image…
2. Set the new image with a name, type set to 8-bit and fill with black
3. Check that Fiji is set to use white as the foreground colour
4. Select the ROI manager window and select More>> 🡪 Fill
5. Some objects may be touching and will need the Watershed function from earlier to separate them.
Select the label image and go to Image 🡪 Adjust 🡪 Threshold
2. Set the threshold to 1 to many
3. Apply the threshold
4. Some objects may be touching and will need the Watershed function from earlier to separate them.
The pretrained model for segmenting H and E nuclei works well too.
Open DAB.tif from Demo Images\Widefield\DAB
2. Go to Plugins 🡪 StarDist 🡪 StarDist 2D. Set the model to Versatile (H and E Nuclei). Leave the other settings the same as before and press OK
3. The probability threshold of 0.70 from before is a little high to select all the nuclei
4. Decreasing the probability threshold down to 0.30 will give a better accuracy
5. Masks of the nuclei can be generate the same way as for the fluorescent nuclei
The process for analysis in 3D uses the same concepts as shown before. Objects need to be thresholded and a watershed needs to be applied to separate objects that are touching. Because the data is 3D then the filters and watershed also need to be 3D variants instead of the 2D variants used before.
Open Nuclei 3D.tif from Demo Image\Confocal\3D Nuclei
2. If you pick a single slice and try to watershed segment it as before for the 2D data, it will not work well at all. Due to the nucleoli staining in each nucleus, each nucleus will fragment into smaller chunks.
3. To smooth out these bright spots a filter needs to be applied, but due to the 3D nature of the data set the filter needs to work in 3D as well. In this case we will apply a Gaussian blur along the three axes of the image; XY and Z.
Go to Process 🡪 Filters 🡪 Gaussian Blur 3D…
4. In the dialog box that comes up enter 2.0 for each of the sigma values. Larger values will apply more blur along the given axis. This means it is possible to blur an image in only one dimension and leave the others unaffected, or apply a stronger blur along say the XY plane to remove hot spots but blur less along the Z axis as it would usually be of a lower resolution anyway.
5. Set the stack to one of the middle slices (number 32 in this example) and go to Image 🡪 Adjust 🡪 Threshold
Set a threshold that selects all of the stain. This threshold will not be applied but we need to read off the number that is shown for the minimum threshold value so we can use it in the next step. For this example to the value is 8995 which we will just round up to 9000.
6. Reset the threshold so it is longer showing on the image. Go to Plugins 🡪 3D Suite 🡪 Segmentation 🡪 3D Watershed
7. In the dialog that opens set the Seeds Threshold to 1 and the Image Threshold to 9000 (th value determined in the previous step).
The source image needs to be set to the image to watershed (in this case Nuclei 3D).
The Seeds can be set to Automatic with a radius of 2
NOTE: Automatic seeds is much master than providing pre-calculated seeds. Pre-calculating the seeds (the 3D equivalent of the find maxima used before) is very slow to do, as an example a 16 core i9 CPU at 4.4 GHz took 42.5 minutes to calculate the 3D maxima for this image. To calculate 3D maxima go to Plugins 🡪 3D Suite 🡪 Filters 🡪 3D Maxima Finder. While calculating the 3D maxima gives a more accurate segmentation, the difference (in this example at least) is around 2%. In the Demo Images\Confocal\3D Nuclei folder is a file called peaks_Nuclei3D.tif that is the result of the 3D maxima calculation and can be used to try out the difference without having to wait.
8. When you press OK the image will be processed. The progress will be printed in the Log window. The Voxels to Process: number should initially count up and then count down to zero as it progresses through the processing
9. The result will be shown in a new image labelled watershed. This will show all the segmented masks, each mask object has a unique intensity value assigned. This can be better visualised by assigning a different LUT. Glasbey Inverted is usually a good choice as it avoids having similar colours next to each other.
Once the segmentation is complete it is worth checking it to make sure it has worked like expected and to see if there is any refinement that needs to be made.
Right click on the watershed image and choose Duplicate… (or go to Image 🡪 Duplicate…)
2. To easily visualise the 3D data it is best to make it an RGB image. Select the newly duplicated image and go to Image 🡪 Type 🡪 RGB Colour
3. Once converted to RGB go to Plugins 🡪 3D Viewer
4. In the dialog that opens you can set several options. The only two that are used regularly are the Display as and Resampling factor options.
Set Display as to Volume and Resampling factor to 1. Resampling factor of 1 means the 3D display will be the same size as the original image. For larger data sets or lower powered systems the resampling factor an be set to 2 or more to reduce the burden, at the cost of resolution. For example a resampling factor of 2 would have the XYZ resolution of the data set.
5. The data set will be displayed in the ImageJ 3D Viewer. You can hold down the left mouse button and rotate the data around. The mouse wheel will zoom in and out.
When looking at the 3D render of the data you will notice there are some small blobs that are less then the volume of the average nucleus in the image. We can filter these out by their volume using the following steps
Firstly we need to create a binary image of the watershed data. Select the original watershed objects and apply a threshold of 1 to 65535 to select all the objects
2. Press the Apply button and make sure that Black background (of binary masks) is the only box ticked in the Convert Stack to Binary window that comes up. This will ensure that the threshold you set is used for the whole stack
3. The resulting binary mask will not be calibrated. Calibrating the binary mask will be needed to get calibrated volume measurements out.
To calibrate the image go to Image 🡪 Properties and set the values as shown below
4. To be able to filter out the smaller objects we first need to find out how big they are. To do that we need to measure the volumes of each object using the 3D object counter
Go to Analyse 🡪 3D Objects Counter
5. In the 3D Objects Counter v2.0 window set the Size filter to a Min. of 1. Make sure the only box checked is Statistics as all we need for this step is to get a measurement of the volume of each object. Press OK
6. The resulting Results table will list all of the objects and can be used to determine the size of any small chunks or debris versus the objects of interest
Looking through the table you will see there are large objects that are bigger than 200um^3 that are the nuclei we want to keep.
7. Close the Results window, select the binary mask image again and reopen the 3D Object Counter
Set the Size filter Min to 200 (the value we worked out in the previous step), tick Objects box under Maps to show and untick all other boxes
8. A new image will be created that shows the results of the processing without the smaller objects in it. For further analysis we need to reconvert this image back to a binary image. AS before set a threshold from 1 to maximum and apply it.
Now that we have refined masks of each of the objects we can use them to measure values back in the original image.
Reopen the original Nuclei 3D.tif image and close all other images other than the final filtered binary objects
2. Go to Analyze 🡪 3D OC Options
The Parameters to calculate can be set to measure the values of interest. Set the Redirect to: option to the original intensity image, in this example Nuclei 3D.tif. This will make all intensity measurements to be carried out on the intensity image and not the binary.
NOTE: If you want to be able to draw graphs and plots of the results in Fiji DO NOT tick the ResultsTable parameters box
3. Make sure the binary masks is the active image and go back to Analyze 🡪 3D Objects Counter
Tick the Statistics box under Results tables to show: All other boxes can be left unticked
4. The results will be displayed in a results table
5. A distribution of the results can be show by selecting the Results table and going to Results 🡪 Distribution….
6. More complex plots can be generated by selecting the Results table again and going to Results🡪Plot
7. In the resulting Plot From Table dialog you can configure the plot to how you would like. In this example the plot will be the volume of the the objects on the x axis and the mean intensity of each object on the Y axis