brainextractor
A re-implementation of FSL's Brain Extraction Tool in Python.
Follows the algorithm as described in:
Smith SM. Fast robust automated brain extraction. Hum Brain Mapp.
2002 Nov;17(3):143-55. doi: 10.1002/hbm.10062. PMID: 12391568; PMCID: PMC6871816.
This code was originally made for a course project.
https://user-images.githubusercontent.com/3641187/190677589-be019bc6-60e4-4e96-8c71-266285ab0755.mp4
Install
To install, use pip to install this repo:
# install from pypi
pip install brainextractor
# install repo with pip
pip install git+https://github.com/vanandrew/brainextractor@main
# install from local copy
pip install /path/to/local/repo
NOTE: It is recommended to use
brainextractoron Python 3.7 and above.
Usage
To extract a brain mask from an image, you can call:
# basic usage
brainextractor [input_image] [output_image]
# example
brainextractor /path/to/test_image.nii.gz /path/to/some_output_image.nii.gz
You can adjust the fractional intensity with the -f flag:
# with custom set threshold
brainextractor [input_image] [output_image] -f [threshold]
# example
brainextractor /path/to/test_image.nii.gz /path/to/some_output_image.nii.gz -f 0.4
To view the deformation process (as in the video above), you can use the -w flag to
write the surfaces to a file. Then use brainextractor_render to view them:
# writes surfaces to file
brainextractor [input_image] [output_image] -w [surfaces_file]
# load surfaces and render
brainextractor_render [surfaces_file]
# example
brainextractor /path/to/test_image.nii.gz /path/to/some_output_image.nii.gz -w /path/to/surface_file.surfaces
brainextractor_render /path/to/surface_file.surfaces
If you need an explanation of the options at any time, simply run the --help flag:
brainextractor --help
If you need to call Brainextractor directly from python:
# import the nibabel library so we can read in a nifti image
import nibabel as nib
# import the BrainExtractor class
from brainextractor import BrainExtractor
# read in the image file first
input_img = nib.load("/content/MNI.nii.gz")
# create a BrainExtractor object using the input_img as input
# we just use the default arguments here, but look at the
# BrainExtractor class in the code for the full argument list
bet = BrainExtractor(img=input_img)
# run the brain extraction
# this will by default run for 1000 iterations
# I recommend looking at the run method to see how it works
bet.run()
# save the computed mask out to file
bet.save_mask("/content/MNI_mask.nii.gz")
Metadata
Release files for brainextractor 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| brainextractor-0.3.0.tar.gz | 15.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| brainextractor-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.3 kB
Release files / brainextractor-0.3.0.tar.gz
| Download URL | brainextractor-0.3.0.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27788c1d6a86107eb8ca82b9e5276881f41168afbd66d2e3d7364793b1749062
|
|
BLAKE2b-256 checksum How to use checksums |
24bb466eed0ce8186a08774619d0d8a64e1d354f2a8d6caad2c15180c440cfe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / brainextractor-0.3.0-py3-none-any.whl
| Download URL | brainextractor-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abc51a8a42a0ab02688b3019e7bb40f6cb83cfdce0a9defba37db58762f80e3c
|
|
BLAKE2b-256 checksum How to use checksums |
7da10622569f14c50a9b24903400ad6fb02a974d0748fbf74d502c76211373ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|