Deteksi Tuberkulosis dari Citra Chest X-Ray Menggunakan Computer Vision & Machine Learning
π Try the App Here!
Upload X-Ray image β Get instant TB detection results with visualization!
| Nama | NPM | Tugas Utama | |
|---|---|---|---|
| Azhar Maulana | 24/533487/PA/22582 | azharmaulana533487@mail.ugm.ac.id | Preprocessing |
| Revy Satya Gunawan | 24/538296/PA/22835 | revysatyagunawan538296@mail.ugm.ac.id | Segmentation |
| Raditya Nathaniel Nugroho | 24/543188/PA/23069 | radityanathanielnugroho2005@mail.ugm.ac.id | Morphological Processing |
| Benedictus Erwin Widianto | 23/520176/PA/22350 | benedictuserwinwidianto@mail.ugm.ac.id | Feature Extraction + Project Lead |
- β Automated Lung Segmentation - K-Means clustering untuk isolasi region paru-paru
- β Advanced Preprocessing - CLAHE + Gaussian Blur untuk enhancement
- β Multi-Region Detection - Deteksi lung, nodule, dan cavity
- β Feature Extraction - LBP, GLCM, Edge, dan Hough Line features
- β ML Classification - SLDT-MSA (Stacking + Moth Search Algorithm)
- β Interactive Visualization - Real-time visualization dengan Streamlit
- β Morphological Analysis - Complete morphology operations analysis
| Tahap | Teknik | Input | Output |
|---|---|---|---|
| 1. Preprocessing | Grayscale β Gaussian Blur β CLAHE | image_path: str |
preprocessed: np.ndarray (HΓW) |
| 2. Segmentation | K-Means (3 clusters) + Adaptive Threshold | preprocessed |
masks: dict (lung, nodule, cavity) |
| 3. Morphology | Otsu + Erosion/Dilation/Opening/Closing | mask |
morphology_results: dict |
| 4. Feature Extraction | Edge (Canny) + Lines (Hough) + GLCM + LBP | img + lung_mask |
features: dict (14 features) |
| 5. Classification | SLDT-MSA (Stacked Decision Tree + Moth Search) | feature_vector |
prediction: "Normal"/"Tuberculosis" |
- Shape Features (3): Edge Sum, Number of Lines, Corner Count
- Texture Features (2): GLCM Contrast, GLCM Homogeneity
- LBP Features (9): Local Binary Pattern Histogram (9 bins)
- Sumber: Kaggle TB Chest X-ray Database
- Total: 4.200 citra (3.500 Normal, 700 TB)
- Split: 80% Training, 20% Testing (stratified)
- Format: PNG/JPG grayscale images
- Struktur:
data/raw/TB_Chest_Radiography_Database/ βββ Normal/ β 3.500 citra βββ Tuberculosis/ β 700 citra
tb-cxr-detection/
βββ README.md
βββ requirements.txt # Dependencies untuk production
βββ requirements-local.txt # Dependencies untuk development
βββ packages.txt # System dependencies (deployment)
βββ config.yaml # Configuration file
βββ .streamlit/
β βββ config.toml # Streamlit app configuration
βββ app/
β βββ main.py # π¨ Streamlit UI
β βββ pipeline.py # Backend analysis pipeline
β βββ utils/
β βββ visualizer.py # Visualization functions
βββ src/
β βββ __init__.py
β βββ tes.py # Complete pipeline (preprocessing β features)
β βββ preprocessing/
β βββ segmentation/
β βββ morphology/
β βββ classification/
β βββ train.py # Model training (SLDT-MSA)
β βββ test_a.py # Model evaluation
βββ models/
β βββ tb_model_raw.pkl # Trained classifier (Git LFS)
βββ data/
β βββ raw/ # Original dataset (gitignored)
β βββ processed/
β β βββ features/
β β β βββ dataset.csv # Extracted features
β β βββ images/
β β βββ masks/
β βββ mock/ # Sample images for testing
βββ notebooks/ # Jupyter notebooks (development)
βββ tests/ # Unit tests
- Python 3.10 or 3.11
- Git
- (Optional) Git LFS for model file
# 1. Clone repository
git clone https://github.com/benedictuserwinwidianto/tb-cxr-detection.git
cd tb-cxr-detection
# 2. Create virtual environment
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Verify installation
python -c "import streamlit; import cv2; import sklearn; print('β All dependencies installed!')"# From project root directory
streamlit run app/main.py
# App will open at http://localhost:8501Classifier: SLDT-MSA (Stacking Loopy Decision Tree + Moth Search Algorithm)
- Feature Selection: Moth Search Algorithm (MSA)
- Base Learners: Decision Tree + Random Forest
- Meta Learner: Decision Tree
- Optimization: Grid Search (class weight + max depth)
- Upload chest X-Ray image (PNG/JPG)
- Click "π¬ Analyze Image"
- View results:
- Prediction (Normal/TB) with confidence
- Segmentation masks
- Morphological operations
- Extracted features
# Generate features from dataset
python src/tes.py
# Train classifier
python src/classification/train.py
# Test model
python src/classification/test_a.py# Create feature branch
git checkout -b feature/module-name-yourname
# Example
git checkout -b feature/segmentation-revy
# Work β Commit β Push
git add .
git commit -m "Add segmentation module"
git push origin feature/segmentation-revy- Create PR dari feature branch ke
main - Tag:
@benedictuserwinwidianto+ 1 teammate untuk review - Merge setelah mendapat 1 approval
- Delete feature branch setelah merge
preprocess_image(image_path: str) -> np.ndarray- Gaussian Blur (3Γ3)
- CLAHE (clipLimit=2.0, tileGridSize=8Γ8)
segment_lungs(img: np.ndarray) -> dict- K-Means clustering (k=3)
- Adaptive threshold untuk nodule/cavity
apply_morphology(mask: np.ndarray, kernel_size: int) -> dict- Otsu thresholding
- Erosion, Dilation, Opening, Closing
extract_lbp_features(img: np.ndarray, mask: np.ndarray) -> dict- Edge detection (Canny)
- Line detection (Hough)
- GLCM features
- LBP histogram
- Dataset: Tawsifur Rahman et al.
- Streamlit Community
- UGM - Pengantar Citra Digital Course
Project Lead: Benedictus Erwin Widianto
π§ benedictuserwinwidianto@mail.ugm.ac.id
π GitHub Issues