uten4211/T1_T2_FLAIR_MRI
๐ง MRI Simulator: T1-Weighted, T2-Weighted & FLAIR
A simple interactive MRI simulation app built with Streamlit. It loads a high-resolution brain phantom (.mat file) from Google Drive and lets you explore how MRI parameters affect image contrast for three common sequences: T1w, T2w, and FLAIR.
๐ Requirements
- Python 3.10 or higher
- Internet connection (to auto-download the brain phantom on first run)
๐ Getting Started
1. Clone or download this project
git clone <your-repo-url>
cd <project-folder>2. (Optional) Create a virtual environment
python -m venv venv
source venv/bin/activate # macOS / Linux
venv\Scripts\activate # Windows3. Install dependencies
pip install -r requirements.txt4. โ ๏ธ Create Streamlit configuration file (Required)
mkdir -p .streamlitThen create .streamlit/config.toml:
[server]
headless = true
port = 8501
enableCORS = false
enableXsrfProtection = false
[theme]
base = "light"5. Run the app
streamlit run app.pyThe app will open at http://localhost:8501.
Note: On first run, BrainHighResolution.mat (~50 MB) will be downloaded automatically from Google Drive. This only happens once.๐ Project Structure
project/
โโโ .streamlit/
โ โโโ config.toml โ required to avoid configuration error
โโโ app.py
โโโ requirements.txt
โโโ .gitattributes โ Git LFS tracking for large files
โโโ README.md๐น๏ธ How to Use
Use the sidebar sliders to adjust MRI parameters:
- T1-Weighted โ fixed at TR = 600 ms, TE = 15 ms
- T2-Weighted โ responds to TR and TE sliders
- FLAIR โ responds to TR, TE, and TI sliders (set TI โ 2500 ms to null CSF)
๐ฌ MRI Sequences Explained
T1-Weighted
Short TR + Short TE โ highlights fat/white matter, CSF appears dark.
T2-Weighted
Long TR + Long TE โ highlights fluid/CSF (bright), white matter appears darker.
FLAIR
Inversion Recovery that suppresses CSF signal โ making periventricular lesions more visible.
๐ Deploy on Hugging Face Spaces
- Create a new Space at huggingface.co/spaces with Streamlit SDK
- Push all files including
.streamlit/config.tomland.gitattributes - The YAML header in this README is automatically read by Hugging Face to configure the Space
git lfs install
git add .
git commit -m "Initial commit"
git push๐ ๏ธ Troubleshooting
๐ Data Source
Brain phantom data: BrainHighResolution.mat โ loaded from Google Drive (file ID: 1vdV5xDNfAiHvmKuH5DPi1YJ5Ptl927nk).
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
