Automatic Identification and Counting of Blood Cells

Saira Gillani
4 min readAug 19, 2024

--

In the field of medical diagnostics, the accurate identification and counting of blood cells are critical for assessing a patient’s health. The paper Automatic Identification and Counting of Blood Cells proposes a machine learning approach to automate this process, leveraging advanced object detection algorithms to streamline and improve the accuracy of blood cell analysis. In this review, I document my experience implementing the methods described in the paper, using a repository available on GitHub, and provide insights into the process and results.

Block diagram from the paper

Setting Up the Environment

There are two ways to go for the implementation one is to download the dataset and train the model and the other is to download the weights (trained model), dataset and place in the folder. The folder should look something like this

Folder structure

In this article, I will focus more on using already trained model and see the inference results. But if you wish to train the model, you can just follow instructions on the GitHub repo and it will work fine.

Creating the Virtual Environment

The first step in the implementation was setting up the appropriate environment. The code provided in the repository required Python 3.7, so I created a virtual environment using the following commands:

sudo apt-get install python3.7-venv
python3.7 -m venv blood_cell_detection_env
source blood_cell_detection_env/bin/activate

Installing the required libaries

After that I installed all the required libraries using pip as follows

pip install Cython tensorflow-gpu==2.2.0 tf-slim==1.1.0 opencv-python protobuf==3.20 

This setup ensured that all dependencies and packages were managed within an isolated environment, preventing conflicts with other projects.

Getting Started

Run the following command to build cython extension

python setup.py build_ext --inplace

To run the code, enter the following code in terminal

python detect.py

Challenges & Issues

The issues I faced during implementation was the paths mentioned in the code, in the following files cy_yolo2_findboxes.pyx, cy_yolo_findboxes.pyx

Replace the following lines from both files

from nms cimport NMS

TO

from .nms cimport NMS

This is the main issue which I faced, rest most of the issues were due to the environment setup, but if you follow the steps I mentioned above, it will work fine. However, if you face any issues, you can always contact me.

Results and Evaluation

The implementation produced promising results, with the model accurately identifying and counting the different types of blood cells. The performance of the model was in line with the expectations set by the paper, demonstrating the effectiveness of the YOLO framework for this application.

The following figure represents the output of the code.

Output Sample

Output Explanation

The image provided shows the output from the implementation of the Automatic Identification and Counting of Blood Cells algorithm. Here’s a breakdown of what the image represents:

Total Counts: The top bar of the output displays the total count of different types of blood cells identified by the algorithm:

  • RBCs (Red Blood Cells): 17
  • WBC (White Blood Cells): 1
  • Platelets: 1

Detection Visualization:

  • RBCs (Red Blood Cells): These are circled in blue, and each identified RBC is labeled with “RBC.” The algorithm has successfully detected and counted a total of 17 RBCs in this particular image.
  • WBC (White Blood Cells): The single WBC in the image is highlighted with a green circle and labeled “WBC.” WBCs are typically larger and have a more complex internal structure compared to RBCs, which is evident in the image.
  • Platelets: The single platelet is highlighted with a red circle and labeled “Platelets.” Platelets are usually much smaller than both RBCs and WBCs.

In terms of accuracy, the model achieved high precision in detecting RBCs, WBCs, and platelets, with minimal false positives or negatives. The speed of detection was also impressive, making this approach suitable for real-time applications in clinical settings.

In the file detect.py, you can change the input picture from this Line 109:

Input file from the code

Conclusions

Implementing the methods described in “Automatic Identification and Counting of Blood Cells” provided valuable insights into the application of machine learning in medical diagnostics. The process highlighted the importance of careful dataset preparation, hyper-parameter tuning, and the potential of the YOLO framework in automating complex tasks such as blood cell analysis.

This review serves as a testament to the progress being made in the field of medical image processing and underscores the potential for further advancements through the integration of machine learning techniques.

References

Automatic Identification and Counting of Blood Cells.

GitHub Repository

--

--

Saira Gillani
Saira Gillani

Written by Saira Gillani

Data Science Enthusiast - Roboticist

No responses yet