What would healthcare look like if you could determine your blood cell count as quickly and inexpensively as your body temperature? At MATLAB Helper®, we are excited by this possibility and believe that such a future is within sight, thanks to MATLAB Image processing and segmentation techniques!
This blog will demonstrate a simple example of how image processing and segmentation techniques can classify and estimate blood cell count.
The proposed model will segment white blood cells (WBC) and Red blood cells (RBC) and it will count them despite they are overlapped or not, by using an algorithm called Circular Hough transform.
Before entering into the algorithm, let's see why this is a fascinating problem space in the first place!
Estimation of Blood Cells and why they’re crucial?
A microscopic image of the blood smear is often used to categorize and identify diseaseconditions that can affect blood cells and to track down those who seek treatment for these conditions. There are many diseases that can affect the count and type of blood cells produced, their function, and their lifespan. Examples include bone marrow disorders, anemia, and leukemia. So understanding the count of Blood Cells in our bloodstream can give us a powerful picture of our health.
Fig1: Examples of disease conditions that affects Blood cell counts
Old conventional method using Hemocytometer and microscope are involving manual counting of blood, which are extremely laborious, time-consuming, and leads to inaccurate results due to human errors. Also, there are some expensive machines like Analyzer, which are not affordable by every laboratory. The proposed method that we will be covering through the rest of this blog is a potentially promising advancement over such techniques due to the following reasons:
Instantaneous results
Low cost
Accurate
less human interactions
Now that we have the necessary background, let’s jump into our particular problem and analyze the dataset, methodology, and results of our method.
Problem:
Given a stained image of a blood smear sample, classify it as either RBC or WBC and estimate it’s count despite its overlapped or not.
Fig 2: Expected outcome
Dataset
The project was fully implemented in MATLAB; the main advantage of this algorithm is that the model does not require training for segmentation. Image segmentation steps are followed for identifying RBC and WBC present in the sample, so it works for the segmentation in smaller data sets. The dataset is composed of a dyed blood sample with overlapped and not overlapped cells. Each image is in PNG format, which is of 440 x 440 pixels size.
Fig 3: Blood smear samples used in our dataset
Prerequisites required
MATLAB App designer and Image processing toolbox
Blood smear samples
Graphical User Interface
For creating the graphical user interface, watch the video given below!
Fig 4: Graphical user interface design using MATLAB app designer tool box
Algorithm Design
The main criterias considered in this method for segmenting RBC and WBC are its shape and size, normally the RBC’s are having a shape similar to circular shape and WBC’s are irregular in shape. Regarding the size, WBC’s are larger than RBCs. So keeping this in mind we are going to create an algorithm to segment RBC and WBC from the blood sample. The whole algorithm can be summarized as follows:
Here are the specific steps followed for cleaning and pre-processing the dataset:
Load blood sample image using imread function
Fig 6: Blood sample image
Convert the given image to gray image using rgb2gray function
Fig 7: Grey Scale image
Increase the contrast of the image using adapthisteq function (optional)
Fig 8: Contrast Enhancement
Then convert this image to binary using imbinarize(I ,graythresh(I) )command for any image I.
Fig 9: Binary image
Step2: Segmentation of WBC’s and RBC’s
The following steps can be used to eliminate platelets and other smaller objects from the image and to segment RBC and WBC.
Usebwareaopen command to reduce noise components such as platelets and other small dots (generally salt and pepper noise).
Fig 10: Noise removed image
Binary inversion of the image to get Blood cells as white (are of interest) and background as black (BW2= ~BW1, where BW2 is a binary inverted image of BW1)
Fig 11: Binary inverted image
Fill the holes using the imfill command (optional)
Usebwareaopen command once again to eliminate all the smaller objects from the image (optional)
Useimerodefunction with a disk-shaped structuring element called strel , to separate the touching border of the cells.
Fig 12: Preprocessed image
Following these steps, you get an image containing only RBC and WBC!
Step 3: Segmentation of WBC
Once the WBCs and RBC’s are segmented we can easily separate them, as the size of WBCs is bigger than RBCs.
The stats = regionprops('table',Segmentedimage,'Area');command can be used to find the area for separating WBC and RBC. This shows the area of all the RBCs and WBCs involved in the image.
Once the area of WBC’s is known they can be separated using the command BW2 = bwareafilt(BW,range),where the range is from the lowest to highest WBC areas. This will extract all the WBC cells within that area range from the image.
Fig 13 : WBC segmented binary mask
Fill the holes using imfill command (if required)
Step 4: Counting of WBC
Use the bwperim function to obtain the edges of the segmented WBC cells and overlay this edge mask on the image.
Fig 14: WBC mask overlay on blood sample
Use bwboundaries or bwconncomp functions to find connected components in binary image. (The number of connected components is same as the WBC count present in the sample).
Step 5: Segmentation of RBC
Follow the same steps as specified in the WBC segmentation; the only difference here is the area range used for RBC segmentation.
The stats = regionprops('table',Segmentedimage,'Area'); command can be used to find the area for separating WBC and RBC. This shows the area of all the RBCs and WBCs involved in the image.
Once the area of RBC’s is known they can be separated using the command BW2 = bwareafilt(BW,range), where the range is from the lowest to highest RBC areas. This will extract all the RBC cells within that area range from the image
Fig 15: RBC segmented binary mask
Fill the holes using imfillcommand (if required)
Step 6: Circular Hough transform for counting overlapped RBC’s
One of the problems encountered while counting the RBC’s is due to overlapping. The cells will appear as a single cell when they overlap each other. So sometimes even for a lab technician, it becomes difficult to differentiate. So manual counting is more tedious and error-prone. In order to count the overlapped cells in the RBC, we need to consider the fact that RBC’s are having a shape similar to circular shape and WBC’s are irregular in shape. So here in this method, we are using a circular Hough transform, which is an algorithm used to identify the circular objects in an image. The accuracy of this identification will be reduced when more than 4 cells are overlapping. [NOTE: A good blood sample has not more than three cells overlapping].
Use the bwperim function to obtain the edges of the segmented RBC cells and overlay this edge mask on the image
Fig 16: RBC mask overlay on blood sample
Apply imfindcircles function to perform circle Hough transform and use length(centres) to get the RBC count.
Here A is the input image and Rmin and Rmax are the radius range of the circular objects or in other terms the RBC’s you want to detect. Specify a relatively small radius range for better accuracy. In this code, we have used [20, 50] in place of [Rmin, Rmax]. Object polarity indicates whether the circular objects are brighter or darker than the background, specified as the comma-separated pair consisting of 'ObjectPolarity' and either of ‘bright’ or ‘dark’. Here in this application RBC’s are brighter than the background. Therefore it’s specified as 'ObjectPolarity','bright'. Sensitivity specified as the comma-separated pair consisting of 'Sensitivity' and a number in the range [0,1]. As you increase the sensitivity factor, imfindcircles detects more circular objects, including weak and partially obscured circles. Higher sensitivity values also increase the risk of false detection. Since RBCs are not perfect circles and having a biconcave disk shape it's highly recommended to use a higher sensitivity value of 0.9. imfindcircles detects more circular objects with both weak and strong edges when you set the edge threshold to a lower value. It detects fewer circles with weak edges as you increase the value of the threshold. So in order to count all the RBC’s present in the sample, it’s advisable to use a lower edge threshold value of 0.1. The accuracy of detection of overlapped blood cells is higher when we precisely tune these input parameters. The circle centers and its corresponding radius values obtained using this algorithm is stored into the output parameters called centers and radii. Therefore the length of centers will give you the count of overlapped RBC’s present in the sample.
Conclusion
We hope the results and methodology shared here provide an overview of how promising image processing and segmentation tools are in the field of cell imaging and classification. As you can see in the picture below, this algorithm was even successful in three overlapping areas for counting the RBC.
Fig 18: Overlapped cells identified through Circular Hough Transform
In certain cases the stains are misclassified as cells but, this algorithm differentiates the stains from RBC cells based on its circular shape and counts only the RBC’s.
Fig 19: Correctly predicted RBC cells by eliminating stain issues
The model and problem statement discussed in this blog are simple, and we believe that they can be extended to more complex issues with multiple classes, new cell types and more varying illumination conditions. We encourage you to extend this code not only for WBCs and RBCs but also a wide variety of other cells such as platelets, sickle cells, and even acanthocytes. If you have any queries regarding the algorithm or if you stuck with your code, you can type them in the comment section below and we will help you with that 🙂 !
If you have any requirement similar to this and you are looking for expert's help, do send the email with necessary attachment at [email protected]
Limitations
Like we already mentioned this post is simply meant to showcase how effective MATLAB image segmentation and Circular Hough transform can be on traditional problems in counting overlapped blood cells. There are a few limitations to this methodology! Here they are:
Our dataset had only a few blood samples. Moreover, most images are under the same lighting and microscopy conditions and it would be worth obtaining images under more varied conditions to prove generalizability.
The main criterias considered in this method for segmenting RBC and WBC are its shape and size. But there are disease conditions where it will affect the shape and size of Blood cells, for example, red blood cells become shorter after bitten by an infected mosquito (malaria infection) and similarly during Sickle cell anemia it causes normally oval-shaped red blood cells to assume a sickle shape. Therefore this method represents a small subset of this overall problem space. But as future work, we can provide a range of metrics for the prediction of varying disease conditions.
Classification elements such as blood cell area, radius have been fixed in the code, and in the future, these parameters can be entered by the user through the GUI to generalize this code for different scaled blood sample images.
The proposed algorithm can be performed on partially overlapped cells, but this algorithm will fail when the RBCs are completely stacked one above another
Reference:
Watch the video below for the full code and try to replicate all the results yourself 🙂
Download the above standalone installation file in .exe format to your computer, which is the standard extension for the installation files on Windows computers. You can follow the steps below to install a stand-alone application from an .exe file.
Locate and double-click the .exe file saved to your computer. (It will usually be in your Downloads folder)
Wait until the following dialog box disappears.
Click on Next
If you want to add a shortcut to the desktop, tick the checkbox, and then click Next.
Click Next
Choose Yesand ClickNext
ClickInstall
Wait for installation to finish. Once this is done, you can now open the app from the Start menu (Windows 7) or the Start screen (Windows 8) by searching for the app name. Alternatively, you can click on the saved shortcut on the desktop.
Did you find some helpful content from our video or article and now looking for its code, model, or application? You can purchase the specific Title, if available, and instantly get the download link.
Thank you for reading this blog. Do share this blog if you found it helpful. If you have any queries, post them in the comments or contact us by emailing your questions to [email protected]. Follow us on LinkedInFacebook, and Subscribe to our YouTube Channel. If you find any bug or error on this or any other page on our website, please inform us & we will correct it.
If you are looking for free help, you can post your comment below & wait for any community member to respond, which is not guaranteed. You can book Expert Help, a paid service, and get assistance in your requirement. If your timeline allows, we recommend you book the Research Assistance plan. If you want to get trained in MATLAB or Simulink, you may join one of our training modules.
If you are ready for the paid service, share your requirement with necessary attachments & inform us about any Service preference along with the timeline. Once evaluated, we will revert to you with more details and the next suggested step.
Education is our future. MATLAB is our feature. Happy MATLABing!
Image Processing & Signal Processing Expert with 4 years of experience in MATLAB Programming. Graduated with a Master’s in Technology degree from VIT University, Vellore, India
Hello Kazi. We don’t share code for our Webinars but we do share the Standalone Application. The Standalone application for the current topic is added in the end of this blog. You can use that for your research purpose. For code you will have to follow step by step process from the video only! All the best!
Hi! Would it be possible to get access to the code you presented here for research purposes? Thanks!
Hello Fareeha. We don’t share code for our Webinars but we do share the Standalone Application. The Standalone application for the current topic is added in the end of this blog. You can use that for your research purpose. For code you will have to follow step by step process from the video only! All the best!
algorithm will fail when the RBCs are completely stacked one above another is the limitation right! do we have a different approach to overcome that? I am curious to know wether we can process two or more 2D images of a 3D object (consider any)from different orientations and give an aggregate result giving more precise and accurate information of the object
Hello Thank you so much for your good explanation. I followed the steps and I and understood the essence of the project, although I don’t have that much experience in image processing. But I have a question about counting RBCs. I dowloaded the Hough Transform function and read it well. But I can’t make the algorithm that much of accurate because of the optional inputs control. So could you suggest a good values for radrange, grdthres, fltr4LM_R, and multirad so it can fits with the RBCs counting. Thanks in advance
Good Work Chotuze..
Thank you for your valuable Feedback!
Good effort
Thank you for the feedback. You can also subscribe to our Youtube channel at https://mlhp.link/YouTube for upcoming events
Good work….
Thank you for your valuable Feedback!
Gud explanation
Thank you for your valuable Feedback!
Great work
Thank you for the feedback. You can also subscribe to our Youtube channel at https://mlhp.link/YouTube for upcoming events
Fascinating application!
Thank you for the feedback. You can also subscribe to our Youtube channel at https://mlhp.link/YouTube for upcoming events
Hi @Ceethal Piyus,
It would be very helpful to me if you provided the code as well as some data sets of microscopic blood sample image.
Hello Kazi. We don’t share code for our Webinars but we do share the Standalone Application. The Standalone application for the current topic is added in the end of this blog. You can use that for your research purpose. For code you will have to follow step by step process from the video only! All the best!
Hi! Would it be possible to get access to the code you presented here for research purposes? Thanks!
Hello Fareeha. We don’t share code for our Webinars but we do share the Standalone Application. The Standalone application for the current topic is added in the end of this blog. You can use that for your research purpose. For code you will have to follow step by step process from the video only! All the best!
algorithm will fail when the RBCs are completely stacked one above another is the limitation right! do we have a different approach to overcome that?
I am curious to know wether we can process two or more 2D images of a 3D object (consider any)from different orientations and give an aggregate result giving more precise and accurate information of the object
In which unit rbc count is expressed here…..?????
how to convert this count value to normal unit…????
How can i get the dataset image?
Hello
Thank you so much for your good explanation. I followed the steps and I and understood the essence of the project, although I don’t have that much experience in image processing.
But I have a question about counting RBCs. I dowloaded the Hough Transform function and read it well. But I can’t make the algorithm that much of accurate because of the optional inputs control.
So could you suggest a good values for radrange, grdthres, fltr4LM_R, and multirad so it can fits with the RBCs counting.
Thanks in advance
Ma’am,I need code of rbc+wbc+platelets ?
Excellent description. Would love to try this.
Good concept and nice explanation of code.
This is so good and i saw your video in YouTube about the blood cell count.
But i have a problem, i need the source code and data sample figure of your video.
Could you please provide the source code and data sample figure?
It’s will help me a lot. If possible please provide me.
Thank you