Method Article
This article describes step-by-step methods to automate image-based nuclei quantification using an open-source executable program validated across a range of cell densities. This program provides an alternative that addresses barriers related to cost, accessibility for users with limited technological skillsets, and application-specific validation that may limit utility of existing technologies.
Live cell assays and image-based cell analyses require data normalization for accurate interpretation. A commonly used method is to stain and quantify nuclei, followed by data normalization to nuclei count. This nuclei count is often expressed as cell count for uninucleate cells. While manual quantification can be laborious and time-consuming, available automated methods may not be preferred by all users, may lack validation for this specific application, or may be cost-prohibitive. Here, we provide step-by-step instructions for capturing quantifiable images of nuclei stained with fluorescent DNA stains and subsequently quantifying the nuclei using an automated object counting software program developed using Python computer vision libraries. We also validate this program across a range of cell densities. Although the exact time for program execution varies based on the number of images and computer hardware, this program consolidates hours of work counting nuclei into seconds for the program to run. While this protocol was developed using images of fixed, stained cells, images of stained nuclei in live cells and immunofluorescence applications can also be quantified using this program. Ultimately, this program provides an option that does not require a high degree of technological skill and is a validated, open-source alternative to aid cell and molecular biologists in streamlining their workflows, automating the tedious and time-consuming task of nuclei quantification.
Functional and image-based experiments are critical for understanding the impacts of experimental treatments on whole-cell biochemistry and physiology. Valid interpretation of data from cell biology experiments depends on the accuracy and reproducibility of the experimental protocol, including data normalization. For example, analyses of oxygen consumption and extracellular acidification rates in live cells at baseline and after treatment with specific drugs allow for the assessment of various aspects of energy metabolism1,2. Measuring the activity of enzymes such as lactate dehydrogenase in the supernatant of cell cultures can aid in quantifying cell membrane integrity3. Staining cultured cells with annexin V and propidium iodide before fixation allows for the assessment of apoptotic and necrotic cells4. However, differences in cell density across wells affect the results of each of these assays. Relying solely on seeding density could provide misleading results due to errors in counting cells for seeding, variations in cell density in media while plating, or different rates of cell growth between samples or treatments throughout experiments. Therefore, normalization of experimental results is required.
Current normalization methods for functional and image-based cell data include protein concentration5 or nuclei or cell count6. To normalize data to protein concentration, cells must be extracted in equal volumes of lysis buffer with protease inhibitor after the assay is run, and an additional assay (e.g., bicinchoninic acid assay, Bradford assay, etc.) must be performed for protein quantification. The accuracy of this method relies on complete cell extraction; leaving any protein behind contributes to errors in quantification. Counting nuclei or cells provides an alternative where no cells need to be removed from the surface on which they are grown. Instead, live or fixed cells are stained or counter-stained using colorimetric or fluorescent stains, and counting can be performed based on images of whole cells or only nuclei. Quantifying nuclei is preferred over whole cells for fluorescence microscopy applications and to normalize data in fused cells (e.g., myotubes) or tissues. For quantification of nuclei using a fluorescence approach, fluorescent DNA dyes (e.g., 4′,6-diamidino-2-phenylindole dichloride (DAPI), Hoechst 33342, Hoechst 33358, DRAQ5, etc.) are applied to live or fixed cells and imaged using fluorescence microscopy. DAPI, Hoechst, and DRAQ5 preferentially bind to adenine-thymine-rich regions of DNA7,8,9, providing a means for detecting nuclei. Optimization of dye concentration prevents off-target binding (i.e., to mitochondrial DNA, causing punctate cytosolic fluorescence)10. The optimization process can be streamlined by using commercially available mounting media containing DAPI for fixed cells (e.g., VECTASHIELD Antifade Mounting Medium with DAPI) and published concentrations of stains for live cells (e.g., Hoechst)6,11,12. Once stained, nuclei in live or fixed cells are visualized using the appropriate excitation filter (e.g., ultraviolet [DAPI and Hoechst] or far-red [DRAQ5]). Excitation maxima for DAPI, Hoechst, and DRAQ5 are at either end of the spectrum for fluorescence microscopy. This attribute, plus the DNA specificity of these dyes and their use at optimal concentrations, minimizes off-target fluorescence. The resulting images show bright nuclei against a black background, and these nuclei are quantified as a measure of cell number for uninucleate cells. While other accurate stain-based methods of nuclei quantification exist using histological stains and brightfield microscopy13, automation is more difficult, albeit possible, using those approaches.
While it remains the gold standard, manual nuclei quantification is laborious, time-consuming, and susceptible to potential human error with prolonged counting. Although automated cell counting programs exist, they are not preferred by all users, may be cost-prohibitive, and validation for specific applications may be minimal. Python has become a valuable and accessible resource for biologists in recent years. Python computer vision libraries are particularly useful for image analysis14. Here, we provide step-by-step instructions for using our executable program developed using Python code to quantify nuclei stained with fluorescent dyes and imaged using fluorescence microscopy. Coding skills are not necessary to use the program described here. This workflow is specific to cells or tissues with fluorescent DNA dyes applied. It is not intended for use with brightfield images. Section 1 describes how to capture and save images collected using fluorescence microscopy in a manner compatible with this workflow. Section 2 provides instructions for running the nuclei quantification program as an executable and fetching output. The executable program can be run directly from the .exe file provided and requires no modifications to quantify nuclei in quality images. This executable requires a Windows-based PC. Section 3 provides instructions for running the program as a Python script rather than an executable (required for Mac- or Linux-based systems, optional for Windows-based systems) and allows for tuning the code if desired. Section 4 describes how to use the results for normalization. These protocols are followed by representative results, including validation data from our laboratory.
NOTE: Supplemental files can be found at the following link https://osf.io/a2s4d/?view_only=2d1042eb8f7c4c4a84579fe4e84fb03c
1. Capturing and saving images using fluorescence microscopy
Figure 1: Example images of DAPI-stained nuclei. These images depict nuclei at (A) low, (B) medium, or (C) high cell densities with minimal background. Note the varying signal intensity of nuclei across image C; this did not interfere with quantification. Scale bar (C) indicates 100 µm; scale bars should be omitted from images used for nuclei quantification. Please click here to view a larger version of this figure.
2. Running the automated nuclei quantification program as an executable
NOTE: This method, running the program as an executable, is compatible with Windows-based PCs and is the recommended method for Windows OS users. Mac OS or other non-Windows users should run the program as a Python script (see Section 3).
Figure 2: Examples of key parts of the workflow for section 2. (A) Extract files from the Downloads folder, taking care to click on the correct folder as indicated by the arrow to enable extraction (B) to the desired destination in step 2.3. (C) Examples of commands for steps 2.4 and 2.5 and the next command line indicating completion in step 2.6. Note that the file path in step 2.4 (C) matches the location for extraction in step 2.3 (B). Please click here to view a larger version of this figure.
3. Running the automated nuclei quantification program as Python script
Figure 3: Examples of key parts of the workflow for section 3 using Windows OS. To access the code, click the green button labeled Code and (A) download the Zip file (indicated by arrows). (B) Extract by right-clicking on the Zip file (shown in blue) and (C) setting the desired destination. (D) After opening the command prompt, examples of commands for steps 3.3.4 and 3.3.5. Note that the command for step 3.3.5 is all on one line; the text beginning "Obtaining file" on the next line appears after pressing enter (step 3.3.6; i.e., running the command). (E) Examples of commands for steps 3.3.7 and 3.3.8, a progress bar following execution of step 3.3.8, and the command line showing completion in step 3.3.9. Please click here to view a larger version of this figure.
Figure 4: Examples of key parts of the workflow for section 3 using Mac OS. After downloading the code (see Figure 3A), (A) extract by clicking on the Zip file (shown in blue) and setting the desired destination. (B) After opening the terminal, examples of commands for steps 3.4.4 (changing the directory to the code repository) and 3.4.5 (installing pip). (C) Examples of commands for steps 3.4.7 and 3.4.8, a progress bar following execution of step 3.4.8, and the command line showing completion in step 3.4.9. Please click here to view a larger version of this figure.
4. Using counts to normalize experimental data
Each batch image run produces: 1) a set of image files with contours applied showing the outlines of identified nuclei (Figure 5), and 2) a .csv file (spreadsheet) linking image file names and the associated counts. Viewing the contours will allow the user to visually assess the count quality. Specifically, images obtained according to section 1 should have all (or nearly all) nuclei surrounded by a solid green line indicating that the nucleus was counted by the program. These contours were used to tune the program here.
Figure 5: Examples of original images and corresponding contours. (A-C) Examples of original images before analysis and (D-F) corresponding contours after analysis directly below. Scale bar (C) indicates 100 µm; scale bars should be omitted from images used for nuclei quantification. Please click here to view a larger version of this figure.
Validation using initial results
C2C12 myoblasts at varying cell densities were methanol-fixed, counterstained with DAPI in mounting media, and 120 images were obtained at 10x magnification in .jpg file format. The automated program was run with the Image Directory set to the folder containing these images, and the resulting .csv file was saved. Separately, each image was manually quantified by two trained researchers who were blind to the automated counts and to each other's counts. Raw images, contours generated by the automated program, and a results spreadsheet including manual and automated counts are available in the Open Science Framework (OSF) repository (see link in section 1). Intraclass correlation coefficients (ICCs; average measures) were calculated using SPSS Statistics to determine interrater reliability between 1) the two manual counts and 2) the average of the two manual counts and counts obtained using the automated program. Similar approaches have been used to validate other programs designed to quantify objects in images obtained using fluorescence microscopy16,17,18. ICCs were also calculated between average manual counts and automated counts for each quartile to ensure that assessing the whole data set did not mask any potential changes in reliability based on cell density. Quartiles were defined using the 25th, 50th, and 75th percentile cut points based on average manual count, and range from quartile 1 (Q1; lowest cell density) to Q4 (highest cell density). ICCs are reported based on average measures and interpreted based on the following definitions: poor (ICC <0.50), moderate (0.50 ≤ICC <0.75), good (0.75 ≤ICC <0.90), or excellent (ICC ≥0.90)19.
Nuclei per image ranged from 44.5 to 1160 based on manual count averages. Interrater reliability was excellent between the two manual counts (ICC > 0.999, p < 0.0001; Figure 6A) and between average manual and automated counts (ICC = 0.993, p < 0.0001; Figure 6B). Reliability remained excellent across quartiles (Q1: ICC = 0.996, p < 0.0001; Q2: ICC= 0.997, p < 0.0001; Q3: ICC = 0.998, p < 0.0001; Q4: ICC = 0.986, p < 0.0001; Figure 6C-F). The single data point far from the best fit line in Figure 6B represents the image shown in Figure 7. The image has several areas of multiple nuclei grouped together, preventing the computer vision program from recognizing each nucleus. This problem can be fixed by using a shorter exposure time. Table 1 describes how to handle such an image.
Figure 6: Inter-rater reliability. Inter-rater reliability across the full data set (A) between manual rater counts and (B) between automated counts and average manual counts. (C-F) Inter-rater reliability between automated counts and average manual counts by quartile. Reliability expressed as intraclass correlation coefficient (ICC). Please click here to view a larger version of this figure.
Figure 7: Example of an image with two barriers to accurate nuclei quantification. (A) Original image and (B) associated contours. Arrow 1 indicates an area with multiple nuclei clumped together, distorting the round nuclear shape enough to impede software detection of multiple nuclei. This occurs in several locations throughout this image. Arrow 2 indicates a faded halo appearing behind multiple nuclei; this halo appeared bright enough for the software to include it as a nucleus, thereby losing the counts of the multiple nuclei it surrounds. This image represents the single data point far from the best-fit line in Figure 6B, emphasizing the potential problems with these barriers. Scale bar (A) indicates 100 µm; scale bars should be omitted from images used for nuclei quantification. Please click here to view a larger version of this figure.
Our nuclei quantification program has several advantages over existing options: it requires only minimal technological skills, is validated for the specific task of nuclei quantification, and is open-source; the latter overcomes cost-related barriers. Ultimately, this program provides cell and molecular biologists with an additional option to quickly and accurately quantify nuclei in images captured using fluorescence microscopy. Currently available automated nuclei or cell counting programs are not preferred by all users, some are cost-prohibitive, and validation may be minimal or absent for specific applications. Specialized equipment, such as the BioTek Cytation line, is accompanied by technical bulletins validating in situ cell counting using nuclear staining20 in addition to a wide variety of additional applications. While validation data exists and the Cytation product line is widely used, especially when interfaced with Seahorse Extracellular Flux Analyzers to normalize live cell data easily and efficiently, this product can be cost-prohibitive for laboratories with limited equipment funding available. For example, the list price for the base model equipped with four objectives and four filter cubes for fluorescence microscopy exceeded $100,000 US dollars in the calendar year 2024. For those without the means to purchase specialized equipment, open-source software provides cost-free alternatives for image analysis. Open-source software useful for nuclei and cell quantification includes ImageJ (National Institutes of Health, Bethesda, MD, USA; available at 21. Plugins are now available for those who wish to write macro scripts for image processing automation using the ImageJ platform. ImageJ-based cell counting automation using phase contrast or brightfield microscopy with whole-cell images has been previously described22,23. CellProfiler is a widely published application for analysis of cell images stained with fluorescent dyes or standard histological stains, and an early article describing its utility across a range of biological applications is often cited as validation24. However, this manuscript does not validate any particular biological finding, necessitating additional validation and transparency for various automation pipelines used, such as for nuclei counting25. Moreover, while CellProfiler is an efficient software package for cell analysis, not all scientists find it user-friendly. Therefore, we aimed to develop and validate an alternative automated program to quantify nuclei using open-source software. Specifically, we employed existing computer vision libraries in Python to develop this workflow.
This method begins with cells or tissues the end-user has stained using DNA stains such as DAPI26. General guidelines for capturing and saving images in a manner compatible with automation software are provided. Although details may differ with different microscopes and imaging software, the general workflow for section 1 is the same to obtain quantifiable images. If using live samples, care must be taken to ensure appropriate personal protective equipment is worn and the imaging environment is appropriate for those samples (e.g., temperature, percentage of CO2, addition of buffer, etc.)27. While this protocol describes imaging of only the DNA dyes, users can capture other colors of the same area for merging purposes15, and simply copy the nuclear images into a separate folder for use with the quantification program. Imaging should be performed in a dark room with appropriate PPE for live samples and proper disinfection should be used as needed (e.g., with 70% ethanol). Stained samples should be protected from light prior to turning the lights on. Quality image capture is critical for accurate nuclei quantification. Even in images with appropriate exposure time and strong contrast between bright nuclei and a black background, the presence of excessively clumped cells or halos behind groups of cells (see Figure 7) may decrease quantification accuracy. In these cases, exposure times may need to be altered to decrease the intensity of signals, ensuring minimal merging of nuclei signals and minimization of halos while maintaining a strong enough signal to detect the round shapes of nuclei. If those steps are insufficient, imaging an adjacent section of the sample may be necessary. All images for a single experiment must be captured at the same magnification, and the magnification corresponding to the objective used must be properly set in the imaging software. It is especially critical that the objective used for imaging matches the settings on the imaging software when the nuclei count will be extrapolated from the imaged area to the whole well (or slide) area. This step should take place each time the objective is switched but is easily overlooked when setting up the microscope and software. The time required for section 1 varies based on a number of factors (e.g., user experience with fluorescence microscopy, number of images and samples, microscope, etc.). To capture 10-15 images of stained nuclei per well in two 6-well plates, the user should reserve approximately 1-2 h of time.
Once images have been captured and saved in a dedicated folder, they are ready to be quantified. The simplest method for quantification is running this pre-packaged automated program without needing to install Python or any libraries (section 2). It should be noted that the program is prepared as an executable and was packaged using Pyinstaller. Software built using Pyinstaller is commonly flagged by antivirus software. If antivirus software blocks the file from opening, the user should flag the file as safe to proceed. This is critical to successfully perform section 2. Alternatively, any user can opt to run the automated quantification program as a Python script (section 3) rather than an executable, if desired. If the user wishes to run the program using a Mac or Linux operating system, the program must be run through Python. This method does not require Pyinstaller but may be more technically challenging. The step-by-step protocol along with examples, detailed in section 3, aims to remove the technical barriers to running this program as a script. Whether section 2 or section 3 is used to run the program, it is critical to ensure that code is properly entered into command prompts. Example lines of code are included throughout the protocol, and the user should pay careful attention to spacing, quotation marks, and other punctuation. The user should also ensure that the file paths are accurate. It is helpful to have the file paths for the images and output available in a Word document. Commands can also be typed into this Word document and copy/pasted as needed.
As described in section 4, there are multiple approaches to normalize experimental data using counts obtained from this automated nuclei quantification program. For image-based experiments where experimental data include a number of events in each image and a proportion is desired (e.g., proportion of annexin V-positive cells28, the proportion of cells expressing ACE2 receptors29, number of cells that uptake stained particles30, etc.), the experimental data for each image can simply be divided by the resulting count (resulting in a proportion from 0 to 1). Then, the average proportion can be calculated across replicate images from the same slide, dish, or well. If a percentage is desired, simply multiply the final proportions by 100. Finally, these average proportions or percentages can be used in downstream statistical analyses. When the experimental data to be normalized are from functional experiments in live cells (e.g., oxygen consumption rates6,11,12) or from cell culture supernatant (e.g., lactate dehydrogenase activity in supernatant31 or concentration of a specific secreted cytokine32, etc.), the nuclei counts should first be averaged across all images captured from the same well. Then, the nuclei count can be extrapolated to the surface area of the slide (coverslip), well, or dish, or the count can be expressed as a ratio versus a reference sample or condition. Extrapolation to the surface area of the slide, well, or dish is useful to express experimental data versus the number of cells (if using uninucleate cells) from which the data were derived (e.g., oxygen consumed per min per 103 cells). To use this method, the surface area of the slide (coverslip), well, or dish and the area captured in each image must be known. If the sample does not cover the entire surface area available, the experimental data are from a small quantity of supernatant (i.e., expressed as activity or concentration per unit volume), or the image and/or surface area are not known, then the best option is to average nuclei counts across all images for a single sample and express the nuclei count relative to a reference sample or condition. The resulting value is used to correct experimental data for nuclei density or cell density (if using uninucleate cells).
While this method is simple to execute, there are several potential problems about which users should be cognizant. These potential problems, along with possible causes and troubleshooting steps to resolve the issues, are listed in Table 1. The program described here has key advantages compared to existing software; however, several limitations must be acknowledged. The main disadvantage is that the quantification program can only be used with images captured using fluorescence microscopy, not brightfield images. While DAPI-stained images captured at 10x magnification were used to build the program, the program can be used with other DNA dyes and magnifications since the program is built to recognize the morphology of the nuclei rather than color or size. While we validated the accuracy of the program on images containing a variety of cell densities, the end user may have cell densities that fall outside of the range. In this case, we still anticipate accurate counts provided that quality images are obtained; however, the user should carefully check the contours and output to ensure accuracy. For cell culture applications, quantification of nuclei in images is most appropriate for cells in a monolayer. If cultured cells overlap, nuclei may be masked, resulting in an underestimation of nuclei quantity. The two-dimensional nature of quantifying nuclei in images precludes the use of this program for determining the total number of nuclei from cells in suspension, thick tissue blocks, or other three-dimensional applications. However, this program can still quantify nuclei labeled with fluorescent DNA dyes in two-dimensional images captured from three-dimensional models such as thick tissue blocks. The utility of quantifying nuclei in images for the desired application should be determined by the end user.
Problem | Possible Causes | Possible Solutions |
Excessive background in images | Exposure time too high | Reduce exposure time |
Nuclei appear to merge with each other in images | Fluorescent DNA dye concentration too high or too much DNA dye-mounting media | Reduce dye concentration during optimization; use the least possible amount of mounting media |
Nuclei appear too light or some nuclei are not visible | Exposure time too low | Increase exposure time |
Photobleaching | Prevent photobleaching by ensuring stained samples remain stored in the dark and by minimizing exposure of samples to illumination (e.g., by using the minimum exposure time necessary and by turning off illumination when it is not needed such as after an image is captured or while taking notes) | |
Halo effects or non-nucleus-specific shapes appearing | Exposure time too high | Reduce exposure time |
Lint from delicate task wipers or some benchtop protectors in live cells or adhering to fixed cells | Ensure a lint-free environment: minimize use of delicate task wipers when samples are exposed (e.g., in biosafety cabinet for live cells, during fixation and drying of fixed cells, or during staining process); ensure benchtop protectors do not leave lint on slides or plates during staining | |
Other abnormalities on surface of fixed cells/tissues | Handle samples with extreme care and follow proper precautions and best practices during fixing and staining | |
Disturbances in light path | Ensure all parts of the microscope are clean and free of lint and dust; clean outside of slides/plates/dishes with 70% ethanol to remove environmental dust and lint prior to imaging | |
Executable file will not open | Antivirus software blocked the file | Flag the file as safe |
Errors in command prompts | Problems with spacing in command line | Double check that the beginning of the command is typed immediately after the “>” symbol in the command line without a space, that no spaces are present after the open quotation marks for file paths, and that spacing and matches the code provided and the examples. |
Improper cases used in command line | The code is case-sensitive; be sure and use capital and lower-case letters as appropriate | |
Problems with file path | Ensure that the file path indicates the inside of the associated file folder (i.e., the file folder is open when the file path is copied). | |
Problems with the program that are not solved using the troubleshooting steps above | Software or command line problems noted above. | Submit an issue via GitHub. Navigate to https://github.com/rbudnar/nuclei_counter. In the menu bar across the top, select “Issues” (second option, to the right of “Code”). Click the green button on the right-hand side that says “New Issue” to submit. There will be a prompt to login to GitHub before submitting the issue. There will also be an option to create a free account if needed. |
Table 1: Troubleshooting for capturing quality images and running the automated nuclei quantification workflow.
Overall, the methods described herein provide step-by-step details to use the automated nuclei quantification program that we developed using computer vision libraries and validated against manual counts from multiple raters. This program was developed to ensure usability by scientists with various levels of coding-related technological skills, is freely available, and was validated specifically for the task of nuclei quantification. Compared with manual counting, this program will save the end user valuable time and provide accurate and reliable nuclei counts for data normalization.
The authors declare no conflicts of interest.
Funding for this work was provided by the National Institutes of Health/National Institute on Aging (R01AG084597; DEL and HYL) and by start-up funds from Texas Tech University (DEL). The authors would like to thank the Texas Tech University Undergraduate Research Scholars and TrUE Scholars programs for providing financial support to the undergraduate researchers who contributed to this work (REH, MRD, CJM, AKW). We also thank Drs. Lauren S. Gollahon and Michael P. Massett for graciously sharing their laboratory space and equipment.
Name | Company | Catalog Number | Comments |
Computer with access to results file from method 2 or 3 | - | - | See step 2.6 (for Method 2) or step 3.3.9 or 3.4.9 (for Method 3) |
Computer with internet access, modern browser | - | - | e.g., Google Chrome |
Computer with internet access, modern browser, and Windows OS | Varies | Varies | For Mac, Linux, or other OS, use Method 3 |
Computer with software for image capture | Zeiss | AxioVision | Other software is acceptable; must be compatible with the fluorescence microscope |
File location for output (results spreadsheet and image contours) | - | - | Can be a new, empty folder |
Fluorescence microscope | Zeiss | Axiovert 200M | Other fluorescence microscopes are acceptable; must be equipped with appropriate filter cubes, desired objective, and camera |
Folder containing all images to be quantified | - | - | See step 1.12 |
Python version 3.10 or higher | Python | - | Available for free download and installation at https://www.python.org/downloads/ |
Samples to be imaged | - | - | Fixed or live, stained or counterstained with fluorescent DNA dyes |
Spreadsheet software | Microsoft | Excel | Similar spreadsheet software is also acceptable |
Request permission to reuse the text or figures of this JoVE article
Request PermissionThis article has been published
Video Coming Soon
Copyright © 2025 MyJoVE Corporation. All rights reserved