Skip to content

lab-smile/CROWN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

594 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CROWN β€” MRI Segmentation & TES Simulation Suite

A web platform for whole-head MRI segmentation and transcranial electrical stimulation (TES) modeling. Upload a NIfTI MRI volume, run automated tissue segmentation across 12 classes, and optionally simulate tDCS/tACS electric field distributions.

Segmentation

CROWN segments whole-head MRI scans into 12 tissue classes:

Label Tissue
0 Background
1 White Matter (WM)
2 Gray Matter (GM)
3 Eyes
4 Cerebrospinal Fluid (CSF)
5 Air
6 Blood
7 Cancellous Bone
8 Cortical Bone
9 Skin
10 Fat
11 Muscle

Models

Six models spanning three architectures and two coordinate spaces:

Architecture Native Space FreeSurfer Space
GRACE grace-native grace-fs
DOMINO domino-native domino-fs
DOMINO++ dominopp-native dominopp-fs
  • Native space β€” output matches the input MRI's original coordinate system
  • FreeSurfer space β€” output conformed to 1mm isotropic 256Γ—256Γ—256 standard space

TES Simulation

After segmentation, run electric field simulations directly in the browser:

Solver Method Time
ROAST FEM via compiled MATLAB runtime ~10–15 min (fast) / ~20–30 min (standard)
SimNIBS FEM with charm meshing on GRACE segmentation ~1–3 hrs

Configure electrode montages (position, size, current), select simulation quality, and visualize the resulting electric field alongside the segmentation.

Features

  • Upload & Segment β€” Upload a NIfTI (.nii / .nii.gz) and select one or more models
  • Interactive 3D/2D Viewer β€” Niivue-based side-by-side comparison with 14 colormap options; all colormaps render all 12 tissue labels without transparency
  • Per-Panel Controls β€” Independent background visibility toggle per viewer panel
  • Segmentation Legend β€” Color-matched tissue legend synced to the active colormap
  • TES Wizard β€” Step-by-step electrode configuration and simulation workflow
  • Real-time Progress β€” Server-Sent Events stream job status to the browser
  • GPU Scheduling β€” Multi-GPU Redis-backed job queue for concurrent users
  • Result Download β€” Download segmentation outputs as NIfTI files

Architecture

ui_v2/     Next.js frontend β€” deployed on Vercel
api_v2/    FastAPI backend  β€” deployed via Docker Compose

Backend services (docker-compose.yml)

Service Description
redis Job queue and GPU locking
api FastAPI + GPU scheduler + ROAST + SimNIBS

The frontend is deployed on Vercel and communicates with the backend via NEXT_PUBLIC_API_URL.

Deployment

Backend

# Copy and fill in environment variables
cp api_v2/.env.example api_v2/.env

# Start Redis + API
docker compose up -d --build

Required host mounts (set in .env or override defaults):

Variable Default Description
MODELS_HOST_PATH /home/chintan/wws_v2/api_v2/models Pre-trained model weights
FREESURFER_LICENSE_PATH /home/chintan/licenses/freesurfer.txt FreeSurfer license
ROAST_BUILD_DIR /home/chintan/roast11/build ROAST-11 compiled binary
MATLAB_RUNTIME /home/chintan/MATLAB/MATLAB_Runtime/R2025b MCR for ROAST
SIMNIBS_HOME /home/chintan/SimNIBS-4.5 SimNIBS installation

Frontend (local dev)

cd ui_v2
npm install
npm run dev   # http://localhost:3000

Environment Variables

Backend (api_v2/.env)

REDIS_HOST=redis
REDIS_PORT=6379
GPU_COUNT=4
JWT_SECRET=...
HMAC_SECRET=...
ROAST_BUILD_DIR=/opt/roast/build
MATLAB_RUNTIME=/opt/mcr/R2025b
ROAST_MAX_WORKERS=2
SIMNIBS_HOME=/opt/simnibs
SIMNIBS_N_THREADS=8

Frontend

NEXT_PUBLIC_API_URL=http://<server>:8000

Data Flow

  1. User uploads a NIfTI file and selects models + coordinate space
  2. Backend preprocesses the input (RAS orientation, 1mm resampling) and enqueues a job
  3. GPU scheduler assigns the job to an available GPU and runs inference
  4. Progress streams to the frontend via SSE
  5. Results load into the interactive viewer; user can optionally launch a TES simulation

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors