Automated 3D brain registration
If you have any questions, please ask on the forum.
The aim of brainreg is to register the template brain (e.g. from the Allen Reference Atlas) to the sample image. Once this is complete, any other image in the template space can be aligned with the sample (such as region annotations, for segmentation of the sample image). The template to sample transformation can also be inverted, allowing sample images to be aligned in a common coordinate space.
To do this, the template and sample images are filtered, and then registered in a three step process (reorientation, affine registration, and freeform registration.) The resulting transform from template to standard space is then applied to the atlas.
Full details of the process are in the original aMAP paper. Overview of the registration process
pip install brainreg
brainreg /path/to/raw/data /path/to/output/directory -x 2 -y 2 -z 5
- Path to the directory of the images. (Can also be a text file pointing to the files)
- Output directory for all intermediate and final results
You must also specify the pixel sizes, see Specifying pixel size
--downsamplePaths to N additional channels to downsample to the same coordinate space.
--sort-input-fileIf set to true, the input text file will be sorted using natural sorting. This means that the file paths will be sorted as would be expected by a human and not purely alphabetically
--n-free-cpusThe number of CPU cores on the machine to leave unused by the program to spare resources.
--debugDebug mode. Will increase verbosity of logging and save all intermediate files for diagnosis of software issues.
By default, brainreg will use the 25um version of the Allen Mouse Brain Atlas. To use another atlas (e.g. for another species, or another resolution), you must use the
--atlas flag, followed by the string describing the atlas, e.g.:
To find out which atlases are available, once brainreg is installed, please run
brainglobe list. The name of the resulting atlases is the string to pass with the
To change the registration algorithm used, use the
--backend flag. The default is
niftyreg as that is currently the only option.
Input data orientation
If your data does not match the brainglobe default orientation (the origin voxel is the most anterior, superior, left-most voxel, then you must specify the orientation by using the
--orientation flag. What follows must be a string in the bg-space "initials" form, to describe the origin voxel.
If the origin of your data (first, top left voxel) is the most anterior, superior, left part of the brain, then the orientation string would be "asl" (anterior, superior, left), and you would use:
To change how the actual registration performs, see Registration parameters
Full command-line arguments are available with
brainreg -h, but please
get in touch if you have any questions.
Open napari and drag your brainreg output directory (the one with the log file) onto the napari window.
Various images should then open, including:
Registered image- the image used for registration, downsampled to atlas resolution
allen_mouse_25umthe atlas labels, warped to your sample brain
Boundaries- the boundaries of the atlas regions
If you downsampled additional channels, these will also be loaded.
Most of these images will not be visible by default. Click the little eye icon to toggle visibility.
N.B. If you use a high resolution atlas (such as
allen_mouse_10um), then the files can take a little while to load.
napari-brainreg also comes with an additional plugin, for visualising your data
in atlas space.
This is typically only used in other software, but you can enable it yourself:
- Open napari
- Navigate to
Plugin Call Order
- In the
Plugin Sorterwindow, select
select hook...dropdown box
brainreg_standard(the atlas space viewer plugin) above
brainreg(the normal plugin) to ensure that the atlas space plugin is used preferentially.
If you find brainreg useful, and use it in your research, please let us know and also cite this repository:
Adam L. Tyson, Charly V. Rousseau, and Troy W. Margrie (2020). brainreg: automated 3D brain registration with support for multiple species and atlases. 10.5281/zenodo.3991718
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size brainreg-0.2.1-py3-none-any.whl (13.4 MB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size brainreg-0.2.1.tar.gz (13.4 MB)||File type Source||Python version None||Upload date||Hashes View|