This project is a web application for detecting Tuberculosis from chest X-ray images using machine learning.
backend/: FastAPI backend for image processing and prediction.frontend/: React/Vite frontend for user interaction.data/: Dataset directory (downloaded from Kaggle).
- Python 3.8+
- Node.js 16+
- Kaggle API credentials (for downloading data)
The backend handles image segmentation, feature extraction, and model inference.
cd backend
pip install -r requirements.txt
python download_data.py # Download dataset if not already present
python train_model.py # Train the model (saves to model.joblib)
uvicorn app:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000.
Swagger documentation is available at http://localhost:8000/docs.
The frontend provides a modern UI for uploading images and viewing results.
cd frontend
npm install
npm run devThe web app will be available at http://localhost:5173.
- Lung Segmentation: Automatically segments lungs from chest X-rays using image processing techniques (Otsu's thresholding, morphological operations).
- Feature Extraction: Calculates area, perimeter, intensity, and entropy features.
- Machine Learning: Uses a Random Forest classifier to predict TB status.
- Interactive UI: Drag-and-drop file upload, real-time analysis, and visual result display.
- The model achieves ~90% accuracy on the test set.
- Ensure
model.joblibexists in thebackend/directory before starting the API.