Skip to content

Frankthetank7277/BloodCell_Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Classical Feature Extraction and Classification of Human Blood Cells

BIOE 484 — Statistical Analysis of Biomedical Images | Spring 2026 | UIUC

An end-to-end image analysis pipeline that classifies 8 types of human blood cells from microscopy images using classical statistical features — no deep learning. Achieves 0.967 macro F1 with an SVM (RBF kernel) on a 69-dimensional feature vector combining morphological, color, and texture descriptors.

Cell class samples

Results

Model Macro F1 Best Class Hardest Class
SVM (RBF) 0.967 Platelet (1.00) Immature granulocyte (0.915)
Random Forest 0.956 Platelet (1.00) Immature granulocyte (0.896)

Confusion matrix — SVM

Key finding: HSV color features account for 78.8% of total classification importance — Wright-Giemsa staining makes color the dominant discriminator, which is exactly what the biology predicts. Texture contributes 13.0% and morphology 8.2%.

Feature family importance

Pipeline

Raw RGB image (128×128×3)
  → Grayscale (BT.601)
  → Gaussian smoothing (σ=1.0)
  → Otsu's adaptive thresholding
  → Morphological cleanup
  → Contour detection
  → 69 features extracted
  → SVM / Random Forest classification

Feature families (69 total)

  • Morphological (6): area, perimeter, circularity, aspect ratio, solidity, extent — from cell contour
  • Color (48): 16-bin L1-normalized HSV histograms × 3 channels — from original RGB
  • Texture (15): 10-bin uniform LBP histogram + 5 GLCM Haralick properties — from grayscale

Project Structure

BloodCell_Classifier/
├── src/
│   ├── __init__.py
│   ├── preprocessing.py     # 6-stage preprocessing pipeline
│   ├── features.py          # Morphological, color, texture extraction
│   └── classifiers.py       # SVM, Random Forest, evaluation, visualization
├── notebooks/
│   ├── 01_eda.ipynb          # Exploratory data analysis
│   ├── 02_preprocessing.ipynb # Pipeline development and validation
│   ├── 03_features.ipynb     # Feature extraction and quality checks
│   └── 04_classification.ipynb # Training, evaluation, feature importance
├── data/                     # Precomputed feature matrices (.npz)
├── outputs/figures/          # All saved plots and figures
└── requirements.txt

Quick Start

# Clone and set up environment
git clone https://github.com/YOUR_USERNAME/BloodCell_Classifier.git
cd BloodCell_Classifier
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

The dataset downloads automatically via pip install medmnist on first run.

Notebooks should be run in order:

Step Notebook Purpose Runtime
1 01_eda.ipynb Explore class distribution and image characteristics ~1 min
2 02_preprocessing.ipynb Develop and validate the preprocessing pipeline ~1 min
3 03_features.ipynb Extract all features and save to data/ ~34 sec
4 04_classification.ipynb Train SVM + RF, generate all figures ~2 sec

Just want the results? Notebooks 01 and 02 are exploratory — start at 03_features.ipynb if you only want to reproduce the classification results.

Dataset

BloodMNIST from the MedMNIST v2 benchmark (Yang et al., 2023):

  • 17,092 Wright-Giemsa stained microscopy images
  • 8 classes: basophil, eosinophil, erythroblast, immature granulocyte, lymphocyte, monocyte, neutrophil, platelet
  • Pre-defined splits: 11,959 train / 1,712 val / 3,421 test
  • Resolution: 128×128 pixels

Methods

Preprocessing: Grayscale conversion → Gaussian smoothing → Otsu's thresholding → morphological cleanup (hole filling + area opening) → contour detection. Color normalization was evaluated and intentionally excluded — stain consistency across images was confirmed during EDA, making normalization an unnecessary source of variance.

Classification: SVM with RBF kernel wrapped in a StandardScaler pipeline (scaler fit on training data only to prevent data leakage). Random Forest with 200 trees provides built-in feature importance via mean decrease in impurity. Train+val combined for final training since default hyperparameters are used.

Evaluation: Macro F1-score as primary metric (handles class imbalance). Per-class confusion matrices and feature importance analysis.

Limitations

Classical features are interpretable and computationally efficient, but performance is resolution-dependent and assumes consistent staining. Results may degrade on non-standardized clinical samples where stain normalization cannot be safely skipped. Cell overlap and out-of-focus regions — common in real smears — are not handled by this pipeline.

References

  • Yang, J. et al. (2023). MedMNIST v2: A large-scale lightweight benchmark for 2D and 3D biomedical image classification. Scientific Data, 10(1), 41.
  • Haralick, R. M. et al. (1973). Textural Features for Image Classification. IEEE Trans. SMC, SMC-3(6), 610–621.
  • Ojala, T. et al. (2002). Multiresolution gray-scale and rotation invariant texture classification with local binary patterns. IEEE TPAMI, 24(7), 971–987.
  • Otsu, N. (1979). A threshold selection method from gray-level histograms. IEEE Trans. SMC, 9(1), 62–66.

Author

Frank Lato — M.S. Biomedical Image Computing, University of Illinois Urbana-Champaign

About

Classical feature extraction and classification of 8 human blood cell types using the BloodMNIST dataset. Comparison of SVM and Random Forest classifiers on morphology, color, and texture features.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors