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

mri mri-segmentation pituitary registration segmentation
Last synced: 4 months ago · JSON representation ·

Repository

This repository contains code that normalizes head MRIs segments the pituitary gland.

Basic Info
  • Host: GitHub
  • Owner: Pituitary-Normal-Space
  • License: other
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 2.65 MB
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
mri mri-segmentation pituitary registration segmentation
Created about 1 year ago · Last pushed 5 months ago
Metadata Files
Readme License Citation

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 run bash poetry run python main.py

What It Does

The steps it follows are outlined below by broad concept.

  1. Preprocessed the MRIs by completing motion correction, smoothing, and affine transformation of T1 to T2 space
  • Before preprocessing

Unprocessed MRIs

  • After preprocessing

Processed MRIs

  1. Overlay T1 and T2 for visualization purposes (optional)
  • Example

T1 and T2 MRIs Overlated

  1. Coregister to MNI
  • Images moved to MNI space

T1 and T2 MRIs in MNI Space

  1. 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

    Score-based segmentation mask

  • 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

Region-growing segmentation mask

  • 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

Before appendage removal

  • After appendage removal

After appendage removal

Owner

  • Name: Pituitary Normal Space
  • Login: Pituitary-Normal-Space
  • Kind: organization
  • Email: qdy4zt@virginia.edu

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

poetry.lock pypi
  • 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
pyproject.toml pypi
  • fslpy ^3.21.1
  • nibabel ^5.3.2
  • pandas ^2.2.3
  • python ^3.12