GithubHelp home page GithubHelp logo

kristianeschenburg / fragmenter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miykael/parcellation_fragmenter

0.0 2.0 0.0 35.76 MB

Fragments annotation and label files into parameterized number of clusters. Useful to feature extraction and generating null models of cortical maps.

Home Page: https://kristianeschenburg.github.io/parcellation_fragmenter/

License: BSD 3-Clause "New" or "Revised" License

Python 83.41% Jupyter Notebook 16.59%

fragmenter's Introduction

GitHub issues GitHub pull-requests GitHub contributors GitHub Commits GitHub size GitHub HitCount

Fragmenter

Fragments FreeSurfer parcellation annotation in N-equal sized parcels. Besides looking beautiful, such surface parcellation could be used as feature extract for machine learning approaches or similar.

The current version takes either the whole FreeSurfer surface and devides it into N equal sized parcels or it takes a predefined region of interest (ROI), specified by FreeSurfer's aparc.annot file and fragments this region in N equal sized parcels.

The parcellation can be done by using a Gaussian Mixed Model, a Ward or a K-Means approach.

The following figure shows an example of a whole surface fragmentation for 16, 64, 256, 1024, 4096 parcels using a Gaussian Mixed Models approach:

The following figure shows an example of a fragmentation of the primary auditory cortex for 4, 16, 64, 256, 1024 using a K-Means approach:

How to install it

git clone https://github.com/miykael/parcellation_fragmenter.git
cd ./parcellation_fragmenter
pip install -e .

How to run it

For a detailed walk-through of how to use the code, see ./notebooks/Demo.ipynb.

import nibabel as nb # for loading surfaces
from fragmenter import RegionExtractor # for extracting regional indices
from fragmenter import Fragment # main fragmentation class
from fragmenter import colormaps # for generating new colormaps

# Define surface file and annotation file.
# If you are using Gifti-structured data, use ```nb.load()``` instead,
# the vertices and faces will exists as GiftiDataArrays objects
verts, faces = nb.freesurfer.io.read_geometry(
  '../data/hcp/L.sphere.32k_fs_LR.surf.gii')

# Extract region-specific indices
# Likewise, you can also specific an HCP-styped Gifti Label object
# with extension .label.gii.
E = RegionExtractor.Extractor(
  '../data/freesurfer/fsaverage/label/lh.aparc.annot')
parcels = E.map_regions()

# Define set of regions of interest.  These region names are dependent
# on the region IDs in the original annotation / label file.
rois=['temporalpole','inferiortemporal','middletemporal',
  'superiortemporal', 'transversetemporal','bankssts',
      'inferiorparietal','supramarginal']
# Instantiate the fragmentation object and generate the sub-regions.
temporal = Fragment.Fragment(n_clusters=75)
temporal.fit(vertices=verts, faces=faces,
  parcels=parcel_maps, rois=rois, size=15)

# If you want to generate pretty color-scheme with a gradient along the
# inferior-superior axis, do the following:
[_, ctab, names, remapped] = colormaps.get_ctab_and_names(verts,
  temporal.label_)
plotting.view_surf([verts, faces],
  remapped, threshold=0.1, cmap='plasma')

# We can then save the map with:
annot_name = '../data/freesurfer/fsaverage/label/lh.temporal.annot'
F.write(annot_name, use_pretty_colors=True)

How to help with it

There are still many things that can be changed/adapted/added. So please feel free to check-out the issues section for what can be done, fork the project, send me a PR or give us a feedback!

fragmenter's People

Contributors

asidwell avatar ctoroserey avatar kristianeschenburg avatar miykael avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.