1 Introduction

In continuous-flow microfluidics there is a common need for simple, rapid estimation of particle positions in the transverse direction of the fluid flow. The increasing amount of processed sample and volumetric throughput achieved in microfluidics demands for tools of particle detection which can process large amounts of information systematically. This is specially critical in processes intended for Point-of-Care applications (Lakhera et al. 2022).

Areas of interest include particle focusing (Motosuke et al. 2013; Jia et al. 2015; Fernandez-Mateo et al. 2022) and particle fractionation caused by phenomena such as Deterministic Lateral Displacement (DLD) (Calero et al. 2019, 2020), pinched-flow fractionation (PFF) (Yamada et al. 2004; Pødenphant et al. 2015), viscoelastic flow (Liu et al. 2017; Tian et al. 2017) or electrokinetics (Tayebi et al. 2021; Emmerich et al. 2022), among others. For different populations of particles flowing simultaneously, differentiation is critical in order to estimate parameters such as fractionation efficiency or relative concentration (Thomas et al. 2017).

Often the methodology for performing this kind of analysis (summarised in Fig. 1) is not reported (Liang et al. 2010; Liu et al. 2017, 2018) or standardised, and in many occasions relies on manual counting of particles (Ho et al. 2021) or indirect measurements such as fluorescence intensity (Ho et al. 2020) and/or image stacking (Liang et al. 2010). Apart from a time-consuming task, these methods do not provide an estimate of the accuracy of the resulting measurements.

We describe a simple, open-source software tool based on MATLAB programming language (MathWorks, Natick, Massachusetts) for particle detection and classification. It estimates particles centre positions with sub-pixel precision and allows for real-time visualization of the results. It stores particle positions data from all analyzed frames and plots a histogram of particle counts in the transverse direction to the fluid flow. The width of the resulting histograms can be determined in the software, and exporting options allow further processing of the data.

Fig. 1
figure 1

Example of a the initial images of particles flowing in a microfluidic channel and b the final histogram that bins the positions of the particles in the direction transverse to the flow

Fig. 2
figure 2

Workflow of the program while navigating through the tabs. After loading the Video or Image files selecting the first set of parameters, the results are displayed in real-time to allow the user to fine-tune the selection to optimise the image processing. The image or video file is then analysed without visualization to maximise the processing speed. The results can be exported to a MATLAB figure or a text file

2 Running the GUI

The software general workflow is summarised in Fig. 2 and it is openly available at Fernandez-Mateo (2022) . The Graphic User Interface (GUI) contains four tabs (shown in Fig. 3) which are designed to be simple and straightforward to use. Navigating through them in order will result in the detection, visualization and whole file analysis. Finally, the results may be exported to either a MATLAB figure or a text file with the raw data of transverse positions found for further post-processing of the results. Preliminary versions of the software have been tested to work flawlessly on different MATLAB versions (2019b to 2021b) under the main operating systems macOS X, Windows 10 and Ubuntu/LINUX. The final application has been packaged in the 2021b Runtime for Windows 10 operating system, and 2020b for macOS X. These are automatically added during the installation of the software and can be run without the necessity of having MATLAB installed.

2.1 Loading and playback

The software interactively imports data from local folders. This may be video or a sequence of image files from the Load (see Fig. 3a). Supported common image file formats are .bmp, .jpeg, .png, and .tiff. Supported video formats are .avi, .mp4, .m4v and .mj2, but these may depend on the operating system and MATLAB Runtime version installed with the software. When loading video files, the user can select the initial and final frames to be imported.

Once loaded, the frames appear in the graphical screen located at the right-hand side of the GUI window. The software provides play/pause of frames at original or selected rates, displays the images frame by frame, or move to a selected frame, as shown in Fig. 3a.

Fig. 3
figure 3

The four tabs of the Particle Finder App, with the functions described in Sects. 2.12.4

2.2 Configuration of parameters

The specification of the general properties of the frames, as well as the particles to be detected is done in the Config tab of the GUI (Fig. 3b). The user selects the direction of flow on the frame sequence, and also whether the particles are fluorescent or non-fluorescent (i.e. shades in bright-field images).

The next step is background correction. Five different background subtraction options are available depending on the relationship between the target particles and the environment.

Selected frame—A frame without target particles is used as a reference to identify unimportant and static features in the images. The frame number is input below the drop-down menu.

Last frame—If the concentration of particles is low enough so that frames without particles are found, these can be used to set a dynamic background subtraction. This regenerates each time a frame with no particles is detected. This feature is convenient if images have slight variations in background illumination during an experiment. In order to start this process, a seed frame is selected to generate an initial background. The user inputs the seed frame number in the same location as the “selected frame” option below the drop down menu.

AVG—The software averages the intensity of each pixel position over all frames. This is the most versatile type of subtraction since it may be used for fluorescent or non-fluorescent particles.

MIN and MAX—When MIN is selected, the software returns the minimum intensity found in each pixel position for all the evaluated frames. This is normally the most robust background when evaluating fluorescent particles. In the same way, the MAX option selects the maximum intensity of all frames for each pixel position, which is most convenient for non-fluorescent objects.

For a simple robust platform, no correlation of particles is performed between frames. The optimal procedure for identifying objects is binarization of the images to completely isolate the objects and an important parameter in this process is the threshold. The threshold is the intensity value above which the software allocates an intensity value of 1 to a certain pixel position. Else, the value 0 is assigned.

The Particle Finder automatically designates a threshold estimation for the images based on the Otsu method (Otsu 1979). To improve the estimation, the fluorescent nature of the particles and the background subtraction method should be previously selected. The automatically chosen value may be further optimised by the user. To tune the value of the threshold, it is important to consider that the threshold is the intensity value which marks the difference between the targeted particles and the background noise, once the selected background is subtracted from the original frame. The magnitude of this intensity value is measured in the scale of the bit depth of the frames (for example, from 0 to 255 in 8-bit depth images).

The last stage is the detection mode, which is the criterion the software uses to discern a target particle between all pixels that have passed the threshold and noise reduction cuts. Particle Finder provides three different detection modes depending on the particle sizes and shape.

First the Point Particles mode detects particles that occupy single pixels in the frames. To achieve this the software makes use of the MATLAB custom function find, which locates the non-zero elements of a given matrix (here images are represented as matrices). This function is outstandingly fast in detecting particles when compared to the other two detection modes. Also, when this detection mode encounters particles that extend more than one pixel, it automatically removes them from the count. This featured may also be used for a size-based discrimination.

The second detection mode, Arbitrary Shape isolates particles of arbitrary size whose characteristic length is given by input parameter Particle Width, expressed in pixels. The function is regionprops, in the image processing toolbox of MATLAB. This function is flexible in terms of the size of the detected particles and may select sizes much larger than specified. Therefore an option to select a maximum detected area of the objects is included (in square pixels). The versatility of this detection mode lies in its ability to detect arbitrary shapes of any size. The particle position is finally given by the centroid of the detected distribution.

The last available detection mode, Spherical Particles, detects circles with radii ranging between two given input values; with a minimum value of 6 pixels in order to consistently discern circular patterns. If the apparent size of the spherical particles is below 6 pixels, the second detection option may be used. The software uses the function imfindcircles. The power of this algorithm lies in the ability to discern different particles even when they are aggregated due to the condition of spherical shape, while ignoring non-spherical shapes.

Finally, we note that the apparent size in pixels may vary depending on threshold conditions—higher thresholds could cause a reduction of the apparent size of the objects, and this should be considered when selecting the size parameters. However, as the histograms are built on the particle number count and not their intensity integration, the final histogram count is independent of the value set for the threshold as long as it allows the identification of the targeted particles. That is, if two similar but not equal thresholds that properly identify the targeted particles are found (which is often possible when particles are clearly distinguishable from the background), then the resulting histograms are identical.

2.3 Quality control and visualization

Once all parameters have been set, the next tab QC shown in Fig. 3c previews in real time the accuracy of the particle detection for the chosen parameters. This provides a means of fine-tuning the parameters without processing all the frames.

For this purpose, the user inputs a range of frames to preview and the frame rate. Pressing Run QC button, the software displays the original frames with the centres of the detected objects marked with red dots. The visualization can be stopped at anytime by pressing the stop “\(\blacksquare\)” button. For the case where the background is similar in intensity to the detected objects making them difficult to distinguish, the Contrast Stretch option labels the maximum and minimum value of intensity for each frame.

Finally, for the case where the detection parameters are particularly complex to optimise, the tool Advanced QC provides a feature for the user to explore each step in the particle detection for the selected settings and detection mode. Pressing Start takes the user to the first unmodified frame selected. From this point, it is possible to navigate through the different steps of the detection process i.e. background subtraction, binarization, noise reduction and particle identification. At any stage it is possible to move to the adjacent frames at the same detection step.

2.4 Complete analysis, data exploration and exporting

The detection process is summarised as follows: First, the background is subtracted from each frame; next, the resulting image is binarized where the selected threshold and noise reduction filters are automatically applied. Finally the selected detection mode is applied. This process is visually described in Fig. 4.

Fig. 4
figure 4

The three primary steps taken by Particle Finder when detecting particles. a Original unmodified frame, where a non-fluorescent particle is seen in the center of the channel together with a background with uneven illumination. b Frame inverted and background subtracted. c Binarisation and noise reduction filters applied. The red dot marks the position of the particle in the frame assigned by the software. The example is for a 3 \(\upmu\)m bead in a 50 \(\upmu\)m wide channel

Particle Finder is designed to analyse a large number of frames in a single session. The tool was tested with videos up to 3000 frames. To reduce the time taken to analyse a large set of images, pressing the Analyse Video button in the Analysis tab (Fig. 3d), hides the displayed images.

To target the required objects and optimise the computational effort, this software can also select a Region of Interest (ROI). There are two different ways of selecting the ROI: The first is to click-and-drag with the cursor a rectangle of arbitrary shape. An alternative option allows the user to make a more accurate selection of the ROI by adjusting the width of the ROI rectangle in the direction of the fluid flow.

An important step is to configure how the data is processed. Particle Finder stores the transverse positions of the objects independent of their longitudinal position within the ROI. This is the most direct way for particle counting. Although this counting method does not reflect the number of particles detected, since one particle may appear in two or more consecutive frames as they flow, for a large enough number of frames the relative frequency of appearance across the transverse direction to the fluid motion represents the relative concentration of particles in this direction. Therefore, the information that can be extracted from the software meets the requirements for the type of analysis described in the literature.

Following the notation described in Fig. 5, in which the transverse direction to the fluid flow is denoted as \(\hat{y}\) and the longitudinal direction as \(\hat{x}\), we see that for an initial random concentration of particles in \(\hat{x}\), and on average a spacing with distance \({\bar{x}}\), the average time \({\bar{t}}\) it takes for the next particle to cross the same y position is \({\bar{t}} = {\bar{x}}/u(y)\). Here, u(y) is the fluid velocity profile across the section of the channel. Therefore, the number of particles crossing into the ROI on average per unit time \(N_t\) at position y is

$$\begin{aligned} N_t(y)=\frac{u(y)}{{\bar{x}}}. \end{aligned}$$
(1)

This means that the number of particles crossing into the ROI does not properly represent the relative concentration of particles in the flow, but is biased by the particular velocity profile of the fluid. However, the software counts the number of times each particle appears in the ROI.

Fig. 5
figure 5

Illustration of the parabolic profile for a straight channel with a region of interest (ROI) selected. If the concentration of particles is homogeneous along the x direction, for a fixed frame rate the number of counts is proportional to the particle concentration within the channel cross section

If the ROI has a length L in the \(\hat{x}\) direction and frames are taken at a certain rate \(f_r\), the number of times a particle appears in the ROI on average \(N_f\) is

$$\begin{aligned} N_f(y)=\frac{f_rL}{u(y)}, \end{aligned}$$
(2)

so for image sets recorded for long enough time, the total number of counts C as a function of the \(\hat{y}\) direction is the number of particles flowing through the ROI in that period, times the number of frames the particle spends in the ROI,

$$\begin{aligned} C(y) = N_tN_f\Delta t=f_rL\frac{\Delta t}{{\bar{x}}}. \end{aligned}$$
(3)

This demonstrates that the number of counts is not influenced by the velocity profile of the fluid flow but responds to the real relative concentration of particles in the transverse direction, as none of the parameters in (3) depends on y. The reason behind this result is that in the y positions where the fluid flow is faster, the particles cross the ROI more frequently, but as they go faster they appear in fewer frames. These two facts compensate each other to obtain counts proportional to the actual particle concentration in the perpendicular direction to the fluid flow \(\hat{y}\).

Finally, after analysing all frames, the software displays a histogram binning particle positions in the \(\hat{y}\) direction. The user can select the width of the bins in pixels. The software exports the histogram into a MATLAB figure for further processing or as raw data in a text file.

Particle Finder also offers one post-processing option: measurement of the width of particle bands, i.e. the total width of the beam of particles detected or a selected percentage of the concentration. This measurement can be done in the Analysis tab of the software by choosing in the Measure Bandwidth selector either From Median if we want to count the percentage of particles from the median of the distribution, or From Ends if the count is to be made from the ends of the distribution.

3 Example

This section illustrates the operation of Particle Finder with an example video where two distinct particle populations flow in a straight channel. This video is openly available in the Supplementary Information.

In this case, particles flow in a \(50 \times 50\) \(\upmu\)m square cross-section straight microfluidic channel. The particle sample contains two distinct populations: the small particles are 500 nm diameter fluorescent beads, while the larger particles are 2 \(\upmu\)m in diameter and non-fluorescent. They are suspended in an aqueous solution flowing at 7.5 \(\upmu\)l/h.

After loading all the available frames of the .avi file, we start the independent detection of both populations. For the case of the 500 nm beads, we select the “Horizontal” direction of the flow, as in the video the particles are flowing from left to right. This population is fluorescent, so the particles are brighter than the background. This is indicated by selecting the “On” position in the fluorescence switch. Finally we choose the minimum projection of the stack of frames as the background, done by selecting the “MIN” option in the drop-down menu.

All these preconditioning options allow detection of the smaller particles when selecting a binarization threshold of 8 with the second detection mode “Arbitrary Shape”. As seen in the example video, these particles have a typical length of 8 pixels. To avoid counting the 2 \(\upmu\)m particles, we select the “Area Capping” checkbox to avoid particles above a certain area (200 square pixels) being counted.

Moving to the next tab into the QC section, we observe detection of the 500 nm beads, while the bigger particles are not counted. An example frame showing the two populations but with only smaller particles counted is presented in Fig. 6a. Finally, analysing the complete set of frames results in the blue bars of the histogram in Fig. 6c.

Fig. 6
figure 6

Example of different populations of particles flowing simultaneously in a 50 \(\upmu\)m-wide channel. a 500 nm particles detect by the QC in the software. b Larger 2 \(\upmu\)m particles detected whilst ignoring the smaller particles. c Superimposed histogram of particle distribution in the ROI for 500 nm particles (blue bars) and 2 \(\upmu\)m particles (red bars). The position of the channel walls are marked by the dashed vertical lines

Detection of the larger 2 \(\upmu\)m particles requires the third detection mode. Choosing 10 pixels as the minimum particle radius and 40 pixels as the maximum, the smaller beads will be ignored while the targeted particles are correctly identified. To compensate for the brighter objects, the binarization threshold is set as 35. This is seen in the example frame shown in Fig. 6b.

The final relative frequency for the larger particles is shown by the red bars in the histogram of Fig. 6c. For creating this figure, the results from both analysis have been separately exported and combined in a single plot using MATLAB.

4 Conclusions

We have described a computational tool that provides users with no experience in image analysis with a user-friendly software for detection and analysis of particles in a flow. This is particularly useful in the case of microfluidic applications.

Preliminary versions of this software have already been used for previous publications (Fernandez-Mateo et al. 2022; Gillams et al. 2022) with different flow profiles, microchannel geometries and particle fluorescent intensities and size. The code is robust and versatile, and together with a simple GUI, it is very practical and easy to use for applications in particle analysis for microfluidics.