pituitary-segmentation-tool
This repository contains code that normalizes head MRIs segments the pituitary gland.
https://github.com/pituitary-normal-space/pituitary-segmentation-tool
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.4%) to scientific vocabulary
Keywords
Repository
This repository contains code that normalizes head MRIs segments the pituitary gland.
Basic Info
Statistics
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Pituitary Segmentation for Normal Space Generation
Repository containing code that completes segmentation of the pituitary based on supplied unprocessed T1 and T2 MRI images of the human brain in NIfTI (Neuroimaging Informatics Technology Initiative) format.
Currently we support working directly with data from the 100 Unrelated Subjects dataset from the HumanConnectome Project.
How To Use
Takes a directory containing unprocessed MRIs in the following structure:
- unprocessed/
- subject_map.csv: file that contains information about subjects that we have MRIs for
_3TStructuralunproc/ /unprocessed/ - T1wMPR1/<subjectid>_3TT1wMPR1.nii.gz: T1 MRI for subject
- T2wSPC1/<subjectid>_3TT2wSPC1.nii.jz: T2 MRI for subject
Structure can be edited in const.py
Once you have set up this directory structure you can run the main file. It will:
- Create a list of subject objects for each subject in subject map
- Preprocess the MRIs for each
- Overlay the T1 and T2 images
- Coregister T1 and T2 to MNI space (path to this file is defined in const. Please update with your path.)
- Segment the pituitary gland using various methods
Additionally you can run a hyperparameter tuning function that will complete a grid-search over relevant parameters and return the best parameters to maximize the DICE criteria. Please note doing so requires the population of the groundtruthmasks directory. Must contain folders with the title as the subject_id and a mask containing nii.gz file within.
Setting Up Locally
Note: You must have FSL installed on your local machine. Additionally you must access the relevant images to run this script from the Human Connectome Project.
- FSL cannot be run on Windows machines without WSL (Windows Subsystem for Linux). The link above has instructions on this, you can also contact qdy4zt@virginia.edu for help.
- Download our package manager poetry (if you have not downloaded it already)
bash pip install poetry - I have created the pyproject.toml files so you don't have to worry about any of that. Just do the below.
- Add configuration to have venv in project directory
bash
poetry config virtualenvs.in-project true
- Set up virtual environment using poetry
bash
poetry install --no-root
Now try either of these two:
- Now you should have a created venv that you can switch into with the following command
bash poetry shell - Run the program with this command
bash python main.py- If this doesn't work runbash poetry run python main.py- Now you should have a created venv that you can switch into with the following command
What It Does
The steps it follows are outlined below by broad concept.
- Preprocessed the MRIs by completing motion correction, smoothing, and affine transformation of T1 to T2 space
- Before preprocessing

- After preprocessing

- Overlay T1 and T2 for visualization purposes (optional)
- Example

- Coregister to MNI
- Images moved to MNI space

- Pituitary segmentation: creates a ROI around centroid and shifts the centroid iteratively based on the final mask the below methods create.
a. Score-based segmentation: gives each voxel in ROI a score based on distance, intensity, and connectivity with centroid.
- Sample mask via score-based segmentation

b. Region-growing segmentation: starting with the centroid adds X number of voxels to the mask based on similarity with nearest voxels established as part of the mask.
- Sample mask via region-growing segmentation

c. Combine the above
- Sample mask of combined methods
d. Appendage removal: utilizes various methods to smooth mask and remove appendages not believed to be the infundibulum. Can be done without.
- Before appendage removal

- After appendage removal

Owner
- Name: Pituitary Normal Space
- Login: Pituitary-Normal-Space
- Kind: organization
- Email: qdy4zt@virginia.edu
- Repositories: 1
- Profile: https://github.com/Pituitary-Normal-Space
GitHub organization dedicated to generating a normal space for the pituitary gland.
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software please request permission and you can cite it as below."
authors:
- family-names: Marche
given-names: Charbel
- family-names: Van Horn
given-names: John
- family-names: Catalino
given-names: Michael
title: "Pituitary Segmentation Tool"
version: 0.0.1
date-released: 2025-2-17
GitHub Events
Total
- Watch event: 1
- Push event: 19
- Pull request event: 2
- Create event: 1
Last Year
- Watch event: 1
- Push event: 19
- Pull request event: 2
- Create event: 1
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 0
- Total pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: less than a minute
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: less than a minute
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- charbelmarche33 (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- dill 0.3.9
- fslpy 3.21.1
- h5py 3.12.1
- nibabel 5.3.2
- numpy 2.1.2
- packaging 24.1
- pandas 2.2.3
- python-dateutil 2.9.0.post0
- pytz 2024.2
- scipy 1.14.1
- six 1.16.0
- typing-extensions 4.12.2
- tzdata 2024.2
- fslpy ^3.21.1
- nibabel ^5.3.2
- pandas ^2.2.3
- python ^3.12