Brain Tumor Detection: Comparing RAW vs Digital Image Processing (DIP) Pipelines
A comprehensive full-stack machine learning application that compares the effectiveness of RAW and DIP preprocessing pipelines for brain tumor classification using MRI scans. Built with React, TypeScript, and Python FastAPI.
- π Quick Start
- π Abstract
- β¨ Key Highlights
- About the Project
- ποΈ Architecture
- β¨ Features
- π Tech Stack
- π¦ Dependencies & Packages
- π Installation
- β‘ Usage
- π€ Model Training & Performance
- π Deployment
- πΈ Screenshots & Visualizations
- π¬ Research & Clinical Context
- π Folder Structure
- π€ Contributing
- π License
- π‘ Security
- π Code of Conduct
Try the live demo: https://tumor-classifier-raw-vs-dip.vercel.app
- Open the web application
- Upload a brain MRI scan (JPG/PNG)
- Click "Analyze" to get instant predictions
- View side-by-side comparison of RAW vs DIP pipelines
# 1. Clone and install
git clone https://github.com/H0NEYP0T-466/TumorClassifier-RAW-vs-DIP.git
cd TumorClassifier-RAW-vs-DIP
npm install
# 2. Start backend
cd backend
pip install -r requirements.txt
python -m App.main
# 3. Start frontend (new terminal)
cd ..
npm run dev
# Open http://localhost:5173TumorClassifier-RAW-vs-DIP is an advanced medical imaging platform that investigates the impact of preprocessing on brain tumor classification accuracy. This research-oriented application compares two distinct pipelines:
RAW Pipeline:
- Minimal preprocessing (grayscale conversion only)
- Direct feature extraction from MRI scans
- Linear SVM classification
- Baseline performance metrics
DIP (Digital Image Processing) Pipeline:
- Advanced preprocessing: CLAHE (Contrast Limited Adaptive Histogram Equalization)
- Gaussian blur for noise reduction
- Morphological operations for feature enhancement
- PCA dimensionality reduction
- Linear SVM classification with optimized features
Does sophisticated image preprocessing improve brain tumor classification accuracy, or is raw data sufficient?
The platform provides a side-by-side comparison enabling researchers and practitioners to evaluate the cost-benefit tradeoff between computational complexity and classification performance.
- Early Detection: Fast, automated screening of brain MRI scans
- Decision Support: Assists radiologists with preliminary tumor detection
- Accessibility: Web-based interface requires no specialized software
- Transparency: Visual comparison of preprocessing steps builds trust
- π¬ Dual-Pipeline Architecture - Compare RAW vs DIP preprocessing side-by-side
- π§ Brain Tumor Classification - Binary classification (tumor vs no tumor)
- β‘ Linear SVM Classifier - Fast, interpretable machine learning model
- π Real-time Predictions - Upload MRI, get instant results
- πΌοΈ Preprocessing Visualization - Step-by-step DIP pipeline visualization
- π Performance Metrics - Accuracy, precision, recall, F1-score comparisons
- π Modern Web Interface - React 19 + TypeScript + TailwindCSS v4
- π Production-Ready API - FastAPI backend with OpenAPI documentation
- π§ Modular Design - Easy to extend with new preprocessing techniques
- π¦ Deployable - Vercel-ready frontend, scalable backend
TumorClassifier-RAW-vs-DIP is an advanced medical imaging application designed to classify brain MRI scans as either containing a tumor or being tumor-free. The project implements and compares two distinct preprocessing approaches:
- RAW Pipeline: Minimal preprocessing - direct classification on grayscale MRI images
- DIP Pipeline: Advanced Digital Image Processing with CLAHE, Gaussian blur, and morphological operations
The application features a modern React frontend with real-time prediction capabilities and a high-performance FastAPI backend powered by Support Vector Machine (SVM) classifiers.
- Compare effectiveness of RAW vs DIP preprocessing for medical image classification
- Provide an intuitive web interface for real-time brain tumor detection
- Demonstrate production-ready ML deployment with FastAPI
- Visualize preprocessing steps and model predictions side-by-side
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React + TypeScript) β
β ββββββββββββββ ββββββββββββββ βββββββββββββββββββββ β
β β Landing β β Upload β β Results β β
β β Page β β Image β β Comparison β β
β ββββββββββββββ ββββββββββββββ βββββββββββββββββββββ β
β β β β β
β ββββββββββββββββ΄βββββββββββββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β API Client β β
β ββββββββββ¬βββββββββ β
βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β HTTP/REST
βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β Backend (FastAPI + Python) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β API Routes (main.py) β β
β β β’ /health - Health check β β
β β β’ /api/v1/predict - Single model prediction β β
β β β’ /api/v1/predict/compare - Dual comparison β β
β ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββΌβββββββββββββββββββββββββββββββ β
β β Preprocessing Pipeline β β
β β ββββββββββββ ββββββββββββββββ β β
β β β RAW β β DIP β β β
β β β Pipeline β β Pipeline β β β
β β ββββββββββββ ββββββββββββββββ β β
β β β β β β
β β Grayscale CLAHE + Gaussian + β β
β β Only Morphology + PCA β β
β ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββΌβββββββββββββββββββββββββββββββ β
β β SVM Classifiers β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β RAW SVM β β DIP SVM β β β
β β β Model β β Model β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββΌβββββββββββββββββββββββββββββββ β
β β Prediction Results β β
β β β’ Class: Tumor / No Tumor β β
β β β’ Confidence Score β β
β β β’ Preprocessing Steps (DIP) β β
β β β’ Performance Metrics β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Image Upload: User uploads brain MRI scan (JPG/PNG)
- Preprocessing:
- RAW: Convert to grayscale β Extract features β Predict
- DIP: Grayscale β CLAHE β Gaussian blur β Morphology β PCA β Predict
- Classification: Both SVMs predict tumor presence independently
- Results: Side-by-side comparison with confidence scores and preprocessing visualization
| Stage | RAW Pipeline | DIP Pipeline |
|---|---|---|
| 1. Grayscale | β Convert to grayscale | β Convert to grayscale |
| 2. CLAHE | β Skipped | β Contrast enhancement |
| 3. Gaussian Blur | β Skipped | β Noise reduction |
| 4. Morphology | β Skipped | β Feature enhancement |
| 5. PCA | β Skipped | β Dimensionality reduction |
| 6. Classification | β Linear SVM | β Linear SVM |
| Complexity | π’ Low | π‘ Medium |
| Speed | π’ Fast (~50ms) | π‘ Moderate (~150ms) |
| Accuracy | π Baseline | π Enhanced |
- Dual-Model Architecture: Compare predictions from both RAW and DIP pipelines simultaneously
- Real-Time Prediction: Upload MRI scans and get instant tumor classification results
- Preprocessing Visualization: View step-by-step image transformations in the DIP pipeline
- Model Performance Metrics: Access detailed accuracy, precision, and recall statistics
- Modern, responsive UI built with React 19 and TypeScript
- TailwindCSS v4 for sleek, professional styling
- Real-time image upload and preview
- Side-by-side model comparison view
- Interactive preprocessing step visualization
- RESTful API built with FastAPI
- Dual SVM model architecture (RAW + DIP)
- Advanced image preprocessing pipeline (CLAHE, Gaussian blur, morphological operations)
- PCA dimensionality reduction for optimal performance
- Comprehensive logging and error handling
- CORS-enabled for seamless frontend integration
- Type-safe TypeScript implementation
- Comprehensive error handling and validation
- Health check and status monitoring endpoints
- Structured logging for debugging and monitoring
- Scalable architecture for future enhancements
Runtime Dependencies
- Vite plugin for TailwindCSS v4
- Beautiful & consistent icon toolkit
- JavaScript library for building user interfaces
- React package for working with the DOM
- Utility-first CSS framework
Dev Dependencies
- ESLint JavaScript rules
- TypeScript definitions for Node.js
- TypeScript definitions for React
- TypeScript definitions for React DOM
- Official React plugin for Vite
- Pluggable linting utility for JavaScript and TypeScript
- ESLint rules for React Hooks
- ESLint plugin for React Fast Refresh
- Global identifiers from different JavaScript environments
- TypeScript language and compiler
- Tooling for TypeScript with ESLint
- Next generation frontend build tool
Runtime Dependencies
- Fundamental package for scientific computing
- Machine learning library for Python
- Lightweight pipelining and caching for Python
- Computer vision and image processing library
- Modern, high-performance web framework for APIs
- Lightning-fast ASGI server
- Multipart form data parser
- Python logging made simple
- Backported and experimental type hints
Before you begin, ensure you have the following installed:
- Node.js (v18.0.0 or higher) - Download
- Python (v3.8 or higher) - Download
- npm or yarn - Comes with Node.js
- Git - Download
-
Clone the repository
git clone https://github.com/H0NEYP0T-466/TumorClassifier-RAW-vs-DIP.git cd TumorClassifier-RAW-vs-DIP -
Install Frontend Dependencies
npm install # or yarn install -
Install Backend Dependencies
cd backend pip install -r requirements.txt # or using a virtual environment (recommended) python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Verify Model Files
Ensure the pre-trained models exist in the
models/directory:raw_svm_model.pkldip_svm_model.pklraw_metrics.pkldip_metrics.pkl
If models are missing, you'll need to train them first (see Usage section).
cd backend
python -m App.main
# Or using uvicorn directly:
uvicorn App.main:app --reload --host 0.0.0.0 --port 8000The API will be available at: http://localhost:8000
API Documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
In a new terminal:
npm run dev
# or
yarn devThe application will be available at: http://localhost:5173
GET /healthPOST /api/v1/predict
Content-Type: multipart/form-data
file: <MRI_image.jpg>POST /api/v1/predict/compare
Content-Type: multipart/form-data
file: <MRI_image.jpg>npm run build
# Output will be in the 'dist' directory# The backend can be deployed with Uvicorn
uvicorn App.main:app --host 0.0.0.0 --port 8000 --workers 4Dataset:
- Source: Brain MRI dataset (tumor/no tumor classification)
- Training split: 80% training, 20% testing
- Image format: Grayscale MRI scans
- Image size: Standardized to 128x128 pixels
RAW Pipeline Training:
cd backend/Model
python RawDataModel.py- Preprocessing: Grayscale conversion only
- Feature extraction: Flattened pixel values
- Classifier: Linear SVM (sklearn.svm.LinearSVC)
- Hyperparameters: Default LinearSVC parameters
- Training time: ~2-5 minutes (CPU)
DIP Pipeline Training:
cd backend/Model
python DipDataModel.py- Preprocessing: CLAHE β Gaussian β Morphology
- Feature extraction: PCA-reduced features
- Classifier: Linear SVM (sklearn.svm.LinearSVC)
- PCA components: Optimized for 95% variance retention
- Training time: ~5-10 minutes (CPU)
Performance metrics are saved to models/ directory:
raw_metrics.pkl- RAW pipeline performancedip_metrics.pkl- DIP pipeline performance
Typical Results:
| Metric | RAW Pipeline | DIP Pipeline | Improvement |
|---|---|---|---|
| Accuracy | ~85-90% | ~90-95% | +5-10% |
| Precision | ~82-88% | ~88-93% | +6-8% |
| Recall | ~80-87% | ~87-92% | +7-10% |
| F1-Score | ~81-87% | ~87-92% | +6-8% |
Note: Exact metrics depend on dataset and train/test split. Run training scripts to generate current metrics.
Pre-trained models are stored in models/ directory:
raw_svm_model.pkl- RAW pipeline SVM (serialized with joblib)dip_svm_model.pkl- DIP pipeline SVM (serialized with joblib)dip_trainingLOGS.txt- Detailed training logs
Model Size:
- RAW SVM: ~5-10 MB
- DIP SVM: ~3-8 MB (smaller due to PCA reduction)
-
CLAHE (Contrast Limited Adaptive Histogram Equalization)
- Enhances local contrast
- Clip limit: 2.0
- Tile grid size: 8x8
-
Gaussian Blur
- Reduces noise and smooths images
- Kernel size: 5x5
- Sigma: 1.0
-
Morphological Operations
- Opening: Removes small noise
- Closing: Fills small gaps
- Kernel: 3x3 ellipse
-
PCA (Principal Component Analysis)
- Reduces dimensionality
- Retains 95% variance
- Speeds up training and inference
Try it now: https://tumor-classifier-raw-vs-dip.vercel.app
# 1. Build the frontend
npm run build
# 2. Deploy to Vercel
npm install -g vercel
vercel
# 3. Configure environment variables in Vercel dashboard:
# VITE_API_URL = https://your-backend-api.comVercel Configuration (vercel.json):
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"framework": "vite"
}Option 1: Railway
# 1. Install Railway CLI
npm install -g @railway/cli
# 2. Login and deploy
railway login
railway init
railway upOption 2: Render
- Connect GitHub repository
- Set build command:
pip install -r requirements.txt - Set start command:
cd backend && uvicorn App.main:app --host 0.0.0.0 --port $PORT - Add environment variables
Option 3: Docker Deployment
# Dockerfile (backend)
FROM python:3.10-slim
WORKDIR /app
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY backend/ .
COPY models/ /app/models/
EXPOSE 8000
CMD ["uvicorn", "App.main:app", "--host", "0.0.0.0", "--port", "8000"]# Build and run
docker build -t tumor-classifier-backend .
docker run -p 8000:8000 tumor-classifier-backendFrontend (.env):
VITE_API_URL=http://localhost:8000 # Development
# VITE_API_URL=https://your-backend.com # ProductionBackend (No .env needed):
- FastAPI runs with default settings
- CORS configured for local development
- Update CORS origins in
main.pyfor production
Frontend:
- Use lazy loading for images
- Implement code splitting
- Enable Vite build optimizations
- Use CDN for static assets
Backend:
- Use gunicorn with multiple workers
- Implement response caching
- Optimize image preprocessing
- Use async file uploads
Brain Tumors:
- Abnormal growths of cells in the brain
- Can be benign (non-cancerous) or malignant (cancerous)
- Early detection critical for treatment success
- MRI is the gold standard for brain imaging
Challenges:
- Manual MRI analysis is time-consuming
- Requires expert radiologist interpretation
- Inter-observer variability in diagnosis
- Need for fast, automated screening tools
This platform addresses these challenges by:
- Automating initial tumor detection screening
- Standardizing image analysis with consistent preprocessing
- Comparing different preprocessing approaches scientifically
- Providing instant results for preliminary assessment
Research Question:
Does sophisticated digital image processing improve brain tumor classification accuracy compared to minimal (RAW) preprocessing?
Hypothesis: Advanced preprocessing (CLAHE, Gaussian blur, morphological operations) will:
- β Enhance tumor boundary visibility
- β Reduce noise and artifacts
- β Improve feature extraction quality
- β Result in higher classification accuracy
Expected Trade-offs:
- β±οΈ Increased computational time
- π§ Additional preprocessing complexity
- π» Higher implementation maintenance
Current Limitations:
- Binary classification only (tumor vs no tumor)
- No tumor type classification (glioma, meningioma, etc.)
- No tumor size/location analysis
- No multi-modal MRI support (T1, T2, FLAIR)
- No 3D volumetric analysis
- Limited to specific dataset characteristics
For Clinical Use:
- Requires FDA/regulatory approval
- Needs validation on diverse patient populations
- Must be integrated into clinical workflow
- Requires radiologist oversight and final decision
- Needs continuous monitoring and updates
Potential improvements:
- πΉ Multi-class tumor type classification
- πΉ Tumor segmentation and localization
- πΉ 3D volumetric analysis
- πΉ Multi-modal MRI fusion
- πΉ Deep learning models (CNN, ViT)
- πΉ Explainable AI visualizations
- πΉ DICOM format support
- πΉ Batch processing for multiple scans
TumorClassifier-RAW-vs-DIP/
β
βββ backend/ # Python FastAPI backend
β βββ App/
β β βββ Utils/
β β β βββ preprocessing.py # Image preprocessing utilities
β β β βββ logger.py # Logging configuration
β β β βββ __init__.py
β β βββ main.py # FastAPI application entry point
β β βββ __init__.py
β βββ Model/
β β βββ RawDataModel.py # RAW pipeline model training
β β βββ DipDataModel.py # DIP pipeline model training
β β βββ __init__.py
β βββ requirements.txt # Python dependencies
β βββ run_commands.txt # Backend setup commands
β
βββ models/ # Trained ML models
β βββ raw_svm_model.pkl # RAW pipeline SVM model
β βββ dip_svm_model.pkl # DIP pipeline SVM model
β βββ raw_metrics.pkl # RAW model performance metrics
β βββ dip_metrics.pkl # DIP model performance metrics
β βββ dip_trainingLOGS.txt # Training logs
β
βββ src/ # React frontend source
β βββ components/
β β βββ LandingPage.tsx # Main UI component
β βββ assets/ # Static assets
β βββ App.tsx # Root React component
β βββ main.tsx # React entry point
β βββ App.css # Global styles
β βββ index.css # Base styles
β
βββ public/ # Static public assets
β βββ vite.svg
β
βββ .github/ # GitHub configuration
β βββ ISSUE_TEMPLATE/ # Issue templates
β βββ pull_request_template.md # PR template
β
βββ eslint.config.js # ESLint configuration
βββ tsconfig.json # TypeScript configuration (base)
βββ tsconfig.app.json # TypeScript config for app
βββ tsconfig.node.json # TypeScript config for Node
βββ vite.config.ts # Vite build configuration
βββ index.html # HTML entry point
βββ package.json # Node.js dependencies
βββ package-lock.json # Locked versions
βββ README.md # Project documentation
βββ LICENSE # MIT License
βββ CONTRIBUTING.md # Contribution guidelines
βββ SECURITY.md # Security policy
βββ CODE_OF_CONDUCT.md # Code of conduct
We welcome contributions from the community! Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated.
Please read our Contributing Guidelines to get started.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Security is a top priority for this project. If you discover a security vulnerability, please follow our responsible disclosure guidelines.
See SECURITY.md for more information on reporting vulnerabilities.
We are committed to providing a welcoming and inspiring community for all. Please read our Code of Conduct before participating.
Made with β€οΈ by H0NEYP0T-466