# leilakfz/mri_tumor_classification architecture

> Architecture diagram of the GitHub repository leilakfz/mri_tumor_classification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leilakfz/mri_tumor_classification
- Repository: https://github.com/leilakfz/mri_tumor_classification

## Overview

##### Project Type and Purpose
- This is a research‐style image‐classification system focused on binary classification of brain MRI scans.
- It implements three distinct pipelines:
a. Hand‐crafted feature extraction (statistical and wavelet methods).
b. Classical machine learning with PCA + SVM.
c. Deep learning using a pre‐trained ResNet‐18.
- The goal is to compare accuracy and performance of each approach on the same preprocessed dataset.

##### File Structure
- Top‐level directories:
- DeepLearning/
- hand_crafted_model/
- machineL/
- README.md
- Each directory maps to one experimental pipeline.
- hand_crafted_model/features.py, variance_correlation.py, waveletTransform.py
- machineL/svm.py
- DeepLearning/autoEncoder.py, resNet.py
- No separate “data” folder, but the README describes dataset acquisition and preprocessing steps.
- No deployment or config scripts—this is an experimentation framework rather than a production service.

##### Pull Key Insights from the README
- Dataset preprocessing (grayscale conversion, resizing, filtering) is common to all methods.
- Hand‐crafted methods: histogram/statistics and wavelet transforms.
- ML: PCA (50 components) → SVM (C=1.0, gamma=‘scale’).
- DL: ResNet‐18 (ImageNet pre‐trained), tweaked for binary output.
- Evaluation: accuracy comparison across methods.

a. Main Components
- Data Store
– Raw MRI images (source directory or object store).
- Preprocessing Module
– Grayscale conversion, resizing, filtering low‐quality images.
- Hand‐Crafted Feature Pipeline
– Variance/Correlation module
– Wavelet Transform + HOG module
– Feature aggregator
– Classifier (metric decision rule).
- ML Pipeline
– PCA transformer
– SVM classifier
- DL Pipeline
– ResNet‐18 model (with transfer learning)
– Training harness (data loader, optimizer, scheduler)
- Evaluation Module
– Accuracy calculator
– Result logger/plotter

b. Relationships and Data Flow
1. Raw images → Preprocessing Module.
2. Preprocessed images → three parallel pipelines (hand‐crafted, ML, DL).
3. Each pipeline outputs predictions.
4. Predictions → Evaluation Module → Comparative results.
5. Optionally: store trained models/artifacts in a Model Registry.

c. Architectural Patterns & Principles
- Modularity: Separate codebases for each experimental method.
- Pipeline pattern: linear data transformations culminating in a classifier.
- Parallel experimentation: three branches feed a common evaluation framework.
- Reuse: common preprocessing logic used by all pipelines.

d. Key Technologies & Libraries
- Python for orchestration.
- NumPy/OpenCV or PIL for image preprocessing.
- Scikit‐learn for PCA and SVM.
- PyTorch (torchvision) for ResNet‐18, data loaders, and training loop.
- Optionally: Matplotlib/Seaborn for visualizing results.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Raw["Raw MRI Image Store"]:::data
    Pre["Preprocessing Module\n(128×128 grayscale)"]:::pipeline_cpu
    Raw -->|"raw images"| Pre

    %% Hand-Crafted Pipeline
    subgraph "Hand-Crafted Pipeline"
        direction TB
        HCVar["Variance/Correlation\nfeatures"]:::pipeline_cpu
        HCWave["Wavelet Transform + HOG"]:::pipeline_cpu
        HCAgg["Feature Aggregator"]:::pipeline_cpu
        HCClf["Classifier\n(metric decision rule)"]:::pipeline_cpu
        HCVar --> HCAgg
        HCWave --> HCAgg
        HCAgg --> HCClf
    end
    Pre -->|"grayscale images"| HCVar
    click HCVar "https://github.com/leilakfz/mri_tumor_classification/blob/main/hand_crafted_model/variance_correlation.py"
    click HCWave "https://github.com/leilakfz/mri_tumor_classification/blob/main/hand_crafted_model/waveletTransform.py"
    click HCAgg "https://github.com/leilakfz/mri_tumor_classification/blob/main/hand_crafted_model/features.py"

    %% Classical ML Pipeline
    subgraph "Classical ML Pipeline"
        direction TB
        PCA["PCA Transformer\n(50 components)"]:::pipeline_cpu
        SVM["SVM Classifier\n(C=1.0, γ=scale)"]:::pipeline_cpu
        PCA --> SVM
    end
    Pre -->|"grayscale images"| PCA
    click SVM "https://github.com/leilakfz/mri_tumor_classification/blob/main/machineL/svm.py"

    %% Deep Learning Pipeline
    subgraph "Deep Learning Pipeline"
        direction TB
        AutoEnc["Autoencoder Experiment"]:::pipeline_gpu
        ResNet["ResNet-18 Training\n(lr=0.001, epochs=25)"]:::pipeline_gpu
    end
    Pre -->|"grayscale images"| AutoEnc
    Pre -->|"grayscale images"| ResNet
    click AutoEnc "https://github.com/leilakfz/mri_tumor_classification/blob/main/DeepLearning/autoEncoder.py"
    click ResNet "https://github.com/leilakfz/mri_tumor_classification/blob/main/DeepLearning/resNet.py"

    %% Evaluation & Results
    Eval["Evaluation & Metrics"]:::eval
    HCClf -->|"predictions"| Eval
    SVM -->|"predictions"| Eval
    AutoEnc -->|"reconstructions"/predictions?| Eval
    ResNet -->|"predictions"| Eval

    Results["Result Reports / Plots"]:::eval
    ModelReg["Model Registry"]:::data
    Eval -->|"reports & plots"| Results
    Eval -->|"store artifacts"| ModelReg

    %% Documentation
    README["Project Documentation & Overview"]:::data
    click README "https://github.com/leilakfz/mri_tumor_classification/blob/main/README.md"

    classDef data fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef pipeline_cpu fill:#90EE90,stroke:#000,stroke-width:1px
    classDef pipeline_gpu fill:#FFA500,stroke:#000,stroke-width:1px
    classDef eval fill:#D3D3D3,stroke:#000,stroke-width:1px
```
