A Python-based medical image viewer inspired by 3D Slicer, featuring multi-planar reconstruction (MPR), AI-powered organ detection, oblique plane viewing, brain surface visualization, and DICOM orientation classification.
- Multi-Planar Reconstruction (MPR) — Simultaneous Axial, Sagittal, and Coronal views with synchronized reference lines
- Oblique Plane Viewer — Define a custom cut line in the axial view and extract an oblique cross-section with rotation support
- Brain Surface Viewer — Dedicated fourth window for brain surface DICOM visualization (switchable via dropdown)
- AI Organ Detection — Uses Google Gemini API to automatically identify the primary organ in a selected ROI
- DICOM Orientation Classifier — Deep learning model (SAM/ViT-based) that classifies DICOM slices as Axial, Coronal, or Sagittal with confidence scores
- ROI Slice Selection — Select a sub-range of axial slices, apply as active ROI, and export the volume
- Window/Level Controls — Manual sliders plus presets (Brain, Bone, Lung, Abdomen)
- Slice Playback — Animated playback through slices with adjustable speed
- Zoom & Pan — Per-view zoom spinbox and middle-mouse-button panning
- Dark Theme UI — Full dark Fusion-style theme throughout
WhatsApp.Video.2026-02-20.at.3.36.57.PM.mp4
- Python 3.8+
- Windows / Linux / macOS
pip install PyQt5 numpy Pillow google-generativeai scipy scikit-image pydicom torch torchvision| Package | Purpose |
|---|---|
PyQt5 |
GUI framework |
numpy |
Array operations |
Pillow |
Image processing |
google-generativeai |
Gemini AI organ detection |
scipy |
Oblique plane rotation |
scikit-image |
Morphological operations |
pydicom |
DICOM file reading |
torch / torchvision |
Orientation classifier model |
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-namepip install -r requirements.txtAt the top of the main script, update the following constants:
# Your Gemini API key (for organ detection)
API_KEY = "your-gemini-api-key-here"
# Path to brain surface DICOM folder
BRAIN_SURFACE_DICOM_PATH = r"path/to/your/dicom_outlines"If you want to use the DICOM orientation classification feature, you need:
- A fine-tuned model checkpoint at:
D:\task2\orientation code\mri_orientation_finetuned.pth - The MRI Foundation codebase at:
D:\task2\orientation code\mri_foundation-master
Update these paths inside DicomFileManagerWindow.init_classifier() to match your environment.
python main_viewer.py- Click "Open DICOM Manager" to open the classification + file browser window
- Or click "Quick Load DICOM Series" to directly load a folder of DICOM files
- Mouse wheel — scroll through slices in any view
- Click in a view — move the crosshair reference lines in all views
- Middle mouse button drag — pan the image within a view
- Zoom spinbox — zoom a specific view independently
- Load a DICOM series
- In the Axial view, drag the magenta line handles to define your cut plane
- The Oblique View (fourth window) updates in real time
- Use the Rot X spinbox to rotate the extracted plane
- Select "Brain Surface" from the dropdown in the fourth window
- Click "🧠 Load Brain Surface" to load from the configured DICOM path
- Scroll with the mouse wheel to navigate slices
- Click "Select ROI Slices" and choose a start/end axial slice
- Click "Apply ROI" — navigation is then locked to that range
- Click "🔍 Detect Main Organ" — Gemini AI will analyze the ROI and return the organ name
- Click "Export ROI Volume" to save the ROI as a
.npyfile
- Open the DICOM Manager window
- Browse for a
.dcmfile - Click "🎯 Classify Orientation" — the model will output Axial / Coronal / Sagittal with confidence scores and a probability bar chart
├── main_viewer.py # Main application entry point
├── image_loader.py # MedicalImageLoader class (DICOM/NIfTI loading)
├── requirements.txt # Python dependencies
└── README.md
Uses gemini-2.0-flash-exp via the Google Generative AI API. A middle slice from the selected ROI is sent to the model, which identifies the primary organ visible.
A SAM (Segment Anything Model) ViT-B backbone fine-tuned for 3-class classification:
- 0 → Axial
- 1 → Coronal
- 2 → Sagittal
Falls back to a ResNet-50 head if the SAM foundation model is unavailable.
- Go to Google AI Studio
- Create a new API key
- Paste it into the
API_KEYvariable in the script
- The orientation classifier requires the MRI Foundation codebase and a fine-tuned checkpoint — it will show an error if these are not present
- Brain Surface loading requires a valid DICOM directory at the configured path
- Organ detection requires a valid Gemini API key and internet connection
MIT License — see LICENSE for details.
- 3D Slicer — inspiration for the multi-planar viewer layout
- Segment Anything Model (SAM) — backbone for orientation classifier
- Google Gemini — AI organ detection
- pydicom — DICOM file handling
Project Contributer:Ahd Ahmed
Project Contributer:Habiba Ibrahem

