Nighres: processing tools for high-resolution neuroimaging

Abstract With recent improvements in human magnetic resonance imaging (MRI) at ultra-high fields, the amount of data collected per subject in a given MRI experiment has increased considerably. Standard image processing packages are often challenged by the size of these data. Dedicated methods are needed to leverage their extraordinary spatial resolution. Here, we introduce a flexible Python toolbox that implements a set of advanced techniques for high-resolution neuroimaging. With these tools, segmentation and laminar analysis of cortical MRI data can be performed at resolutions up to 500 μm in reasonable times. Comprehensive online documentation makes the toolbox easy to use and install. An extensive developer’s guide encourages contributions from other researchers that will help to accelerate progress in the promising field of high-resolution neuroimaging.

requested in your manuscript?
If not, please give reasons for any omissions below. as follow-up to "Experimental design and statistics Full details of the experimental design and statistical methods used should be given in the Methods section, as detailed in our Minimum Standards Reporting Checklist. Information essential to interpreting the data presented should be made available in the figure legends.
Have you included all the information requested in your manuscript? " Not applicable as this manuscript describes software Resources A description of all resources used, including antibodies, cell lines, animals and software tools, with enough information to allow them to be uniquely identified, should be included in the Methods section. Authors are strongly encouraged to cite Research Resource Identifiers (RRIDs) for antibodies, model organisms and tools, where possible.
Have you included the information requested as detailed in our Minimum Standards Reporting Checklist?

Yes
Availability of data and materials All datasets and code on which the conclusions of the paper rely must be either included in your submission or deposited in publicly available repositories (where available and ethically appropriate), referencing such data using a unique identifier in the references and in the "Availability of Data and Materials" section of your manuscript.
Have you have met the above requirement as detailed in our Minimum Standards Reporting Checklist?

Background
Advances in ultra-high eld (7 Tesla and above) MRI now make it possible to image the whole brain at an unprecedented level of detail [1]. Submillimeter resolutions and quantitative metrics reveal ne-grained variations in structure and function that were previously undetectable in vivo, and allow researchers to ask new questions about the human brain. Examples include the investigation of intracortical myelin [e.g 2, 3, 4, 5], the laminar organization of the cortical sheet [e.g. 6,7,8,9,10], feedforward and feedback patterns in cortical connections [11,12,13] and the detailed description of small cortical and subcortical structures [14,15] and their function [16].
While ultra-high eld scanners have become increasingly available and the rst open 7 Tesla MRI data sets have been released [17,18,19], software tools still lag behind. Standard neuroimaging software packages are often not designed to handle the growing data size and new quantitative contrasts. Three-dimensional MRI data grows as a cube of its resolution, and computational complexity generally ranges between  N) and O(N 2 ). Therefore, a change in spatial resolution from 1 mm to 0.5 mm easily entails an increase in computational requirements by a factor of 15 to 60, depending on the methods used. Moreover, many new applications, such as laminar analysis, have only become possible with higher resolutions and are not implemented in existing software packages.
CBS High-Res Brain Processing Tools (CBS Tools) is a software suite which addresses this gap by providing cutting-edge methods for e cient processing of MR images at submillimeter resolution [20]. For example, CBS Tools implements routine cortical segmentation at resolutions as high as 400 µm, processing of quantitative MRI sequences such as MP2RAGE, MPM or QSM [20], laminar analysis [7], and small vessel segmentation [21]. While this software has been well-received as a key tool set for quantitative and high-resolution neuroimaging, its adoption has been slowed by the complex infrastructure it builds on. CBS Tools have been developed in Java as a set of plugins for the MIPAV software package [22] and the JIST pipeline environment [23]. The MIPAV / JIST framework provides a graphical interface for building analysis pipelines and implements many convenient tools, but it comes with a complex installation procedure, heavy dependencies, and limited documentation. More importantly, it is di cult to integrate with other popular neuroimaging tools, limiting its software ecosystem.
Meanwhile, a range of versatile, interoperable open source packages for the analysis of neuroscienti c data has been developed using the increasingly popular programming language Python [24]. For example, Nipy 1 is a community of practice devoted to the use of Python in the analysis of neuroimaging data, encompassing popular tools such as Nibabel [25], Nipype [26], Nilearn [27] and many others.
Here we present Nighres 2 -a new toolbox that makes the quantitative and high-resolution image processing capabilities of CBS Tools available in Python. Nighres is a user-friendly Python package which interfaces with CBS Tools while avoiding the JIST and MIPAV dependency tree. It facilitates integration with other Python-based neuroimaging tools and interactive data exploration, for example in Jupyter notebooks 3 . Nighres features comprehensive online documentation with usage examples that are based on publicly available data sets. An extensive developer's guide encourages external contributions in Java or Python. With this new package, we aim to make the capacities of CBS Tools accessible to a wider community, highlight the potential of new high-resolution image processing methods, and foster collaboration in this emerging eld.

Architecture and design
The Nighres package consists of two core Python modules. The module cbstools contains the original CBS Tools Java classes that have been encapsulated using the JCC package 4 . JCC encapsulates the Java code with C++ code, to make it accessible to the Python interpreter, and produces a complete Python extension module. The module nighres includes the Python interfaces that are exposed to the user. It is organized in submodules that represent di erent application areas. 5 For example, the submodule laminar contains functions related to laminar analysis of the cortical sheet. The Python interfaces in each submodule are currently of two types: i. Functions that wrap Java classes ii. Functions in pure Python

Functions that wrap Java classes
The initial motivation to develop Nighres was to provide a userfriendly interface to the functionality of CBS Tools, leveraging the exibility of Python. Therefore, a majority of the current functions in Nighres constitute Python wrappers which internally execute the original CBS Tools Java classes. These functions generally adhere to the following basic structure (a simple example can be found in the function probability_to_levelset): i. Evaluate input parameters ii. Start Java virtual machine iii. Initiate Java class through JCC wrapper iv. Load input data and cast to Java array v. Pass additional parameters to Java class vi. Execute Java class vii. Collect outputs of Java class and cast back viii. Return outputs (optional: save outputs) Thus, the actual processing still relies on the same optimized Java code as in the original CBS Tools. However, since the Nighres function takes care of the interfacing between Python and Java, the user only interacts with Python code.

Functions in pure Python
Our long-term vision is for Nighres to become a central platform for new high-resolution image processing tools as they are developed. As discussed above, Python is rapidly becoming the most popular programming language in the neuroimaging community. The modular design of Nighres allows for easy integration of pure Python processing routines, and for the use of other neuroimaging software that has been (or can be) wrapped in Python independently with pipelining tools such as Nipype [26]. In addition, we have included a core set of lightweight convenience functions for input and output, parameter handling, and le naming in Python to simplify function calls and minimize the integration burden for new methods.  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65 Data handling Data handling within Nighres follows established and widely used standards in the imaging community to ensure maximum interoperability. Where possible, Nighres uses the Nibabel package for handling imaging data [25]. Input and output functions are designed to automatically recognize and load most commonly used data formats, while maintaining exibility to accommodate loading of non-standard data formats using custom scripts. Data is internally represented as Nibabel Nifti1Images (volumes) or Python dictionaries (surfaces) and can be passed in the form of le names or memory objects. Processing results are returned as memory objects, functions with multiple outputs return a dictionary storing the di erent outputs. Outputs can also be saved to disk. For saving, modi ers are appended to the output le names that refer to the name of the function and the speci c output (e.g. _layering_depth for the continuous depth output of the volumetric layering function). Output names can be set to have a speci c pre x or, by default, append modi ers to the main input le name.

Distribution
While both Python and Java are cross-platform languages, the JCC package that is used to encapsulate the CBS Tools Java classes generates C++ code and thus makes compilation platform-speci c. We therefore implemented an automated build script that compiles the original CBS Tools Java code and builds the wrappers using JCC. We set up continuous integration using Travis CI 6 to test the build upon any changes to the code base on Github and, for any tagged releases, deploy the package to the Python Package Index 7 . The user can then download the package, run the fully automated build script to recompile the Java code and C++ wrappers on their platform, and nally use the pip installer 8 to install the modules and all their dependencies. Subsequently, Nighres can simply be imported into any Python environment.
We also provide a container allowing users to test Nighres in a preset environment, without actually installing it on their system. For this option the user only has to install Docker 9 , a lightweight container platform that runs on Linux, Windows and Mac OS X. The Nighres Docker le 10 can then be used to build an Ubuntu 14 Trusty Docker image that contains a suitable Java installation, Nighres, and Jupyter Notebook.

Dependencies
One goal of Nighres was to reduce external dependencies. We therefore restricted the required packages for Nighres' core functionality to Nibabel, for reading and writing of common neuroimaging data formats [25], and Numpy, for e cient manipulation of data arrays [28]. The functions wrapping CBS Tools code require the CBS Tools Java library as well the Java matrix manipulation 11 and Apache Commons Math 12 libraries. However, these libraries are automatically recompiled, wrapped and installed from the CBS Tools github repository 13 upon installation of Nighres. Our example work ows use Nilearn's [27] plotting functionality for visualizing their results, but will automatically skip plotting if Nilearn is not installed.

Support les
Nighres automatically installs all essential support les including statistical atlases for brain segmentation, look-up tables for topological constraints, templates for high-resolution spatial normalization, and a cerebellar lobular atlas [29]. In addition, example data from publicly released 7 Tesla data sets is hosted on the Nighres project page 14 at the neuroimaging informatics tools and resources clearinghouse [NITRC,30], and automatically downloaded when running the example work ows (see below).

Documentation
Beyond functional code, clear and concise documentation is one of the most important drivers of software use and longevity. Nighres' online documentation 15 was implemented using the Sphinx documentation tool 16 and automatically generates online content from the original function docstrings, which are written according to the the Numpy/Scipy documentation guidelines 17 . This design ensures that the documentation stays up-to-date with minimal overhead for developers, and is intuitive for users. Extensive example work ows provide users with easily understandable and reproducible code, as described in the following section. Finally, the online documentation contains an in-depth developer's guide that leads contributors through all steps necessary to submit code changes, new Python functions, new wrappers for CBS Tools functions or improvements of the documentation, to the Nighres github repository. We aimed to write a guide that makes it feasible for any researcher working with high-resolution neuroimaging data to contribute to Nighres, even without much previous experience in software development.

Usage example
In the following we present one of Nighres' usage example pipelines. The example shows how to obtain a tissue classication from MP2RAGE data [31] by performing the following steps: i. Downloading the open MP2RAGE data set from NITRC ii. Removing the skull and creating a brain mask iii. Atlas-guided tissue classi cation using a multiple object geometric deformable model (MGDM) [32] The outputs of the plotting functions are shown in Figure 1.

Import and download
First we import nighres and the os module to set the output directory.

Skull stripping
The rst processing step is skull stripping. Only the second inversion image of the MP2RAGE sequence is required to calculate the brain mask. But if we input the quantitative T1 map and the T1-weighted image as well, they will be masked for us. We also save the outputs in the out_dir speci ed above and use a subject ID as the base le name. To check if the skull stripping worked well ,we plot the brain mask on top of the original image ( Figure 1a). Nighres, like Nilearn [27], uses Nibabel [25] Nifti1Image objects to pass data internally. Therefore, we can directly pass the outputs to Nilearn's plotting functions without saving and reloading. Alternatively, the images stored in out_dir can be opened in any common interactive viewer that can read the Nifti data format.
if not skip_plots: plotting.plot_anat(mgdm_results['distance'], vmin=0, → vmax=20, annotate=False, draw_cross=False, This examples implements a complete work ow for advanced processing of a quantitative MR contrast at high spatial resolution (voxel size = 0.5 mm isotropic). With the openly available and automatically downloaded data, any user can try out Nighres' functionality immediately after installation and then adapt the clearly explained code for their own use case.
A B C Figure 1. Tissue classi cation from MP2RAGE data. A The brain mask obtained from skull stripping. (Note that the white rectangles in the image occur because the data has been "defaced" for anonymization) B The segmented brain structures. C A representation of each voxel's distance to their nearest borders for assessing partial volume e ects. Visualization performed within the script using Nilearn [27].

Discussion
We developed a Python toolbox that specializes in processing high-resolution brain imaging data. It has been designed with two key purposes in mind: i. to provide the neuroimaging community with userfriendly access to cutting-edge high-resolution image processing tools, ii. to create a exible framework that can be extended by other researchers, along with thorough instructions on how to contribute.
The availability of high-resolution and quantitative MRI data, and the interest in new research directions that this data enables, are rapidly growing [e.g 33,34]. At the same time, the image processing tools that would be required to leverage the new level of spatial detail provided by this data are largely missing. Only a few major neuroimaging packages have begun to adapt their tools for these purposes [35,36]. However, these packages are limited by their closed source   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65 code or rigid data organization, while it is crucial that newly emerging methods can be exibly adapted, collaboratively developed, and integrated with other tools.
CBS Tools provides dedicated open source methods for high-resolution image processing [20]. Unfortunately, its complex design and heavy dependencies can make the installation and handling challenging for naive users, and impede contributions from other researchers. With Nighres we provide a exible and user-friendly implementation of CBS Tools' functionality, which eliminates the dependency on MIPAV and JIST. Another major advance of Nighres compared to CBS Tools is its extensive online documentation. Besides comprehensives explanation of every function's inand outputs, carefully documented usage examples provide step-by-step instructions of how the di erent tools can be combined to create complete processing pipelines.
The current implementation of Nighres contains a set of cutting-edge methods, but rapid methodological advances are to be expected in the dynamic eld of high-resolution neuroimaging. We therefore designed Nighres as a transparent software platform through which newly developed methods can be made available to the community and improved collaboratively. New or existing tools can easily be added in a variety of formats, depending on the speci c requirements of the operation and the preferences of the developer. The extensive developer's guide aims to encourage contributions even from researchers with little previous experience in software development.
We aimed to closely integrate our package with the existing community around neuroimaging tools in Python. To this end, we adopted standardized objects for internal data handling, which can easily be exchanged with other tools. An example is the seamless visualization of Nighres outputs using Nilearn's [27] plotting functions as showcased in the usage example ( Figure 1).
A major limitation of the current package is that it has been developed and tested for common Linux platforms only. The C++ code generated by JCC to interfaces with the CBS Tools Java classes makes the compilation platform dependent. We addressed this issue by providing an automated build script that recompiles this code upon installation. While this process has only been tested on Linux, the design makes a future adaptation to Mac OS X platforms straightforward. Support for Windows is not currently planned. However, the provided Docker le enables usage of Nighres in a container on any platform that supports Docker.
Many future extension of the current package can be envisioned. Besides integrating more of the original CBS Tools functions, a main goal is to extend functionality with new tools coded directly in Python. To ensure e cient processing of the large data this might require the implementation of critical processes as C-extension through Cython 18 . Another goal is to provide integration with tools for parallel processing and job management on compute clusters.
In sum, we developed a user-friendly and well-documented Python package that makes cutting-edge high-resolution image processing tools available to the research community. The toolbox is easy to install and provides a comprehensive set of advanced techniques. While the current functionality is 18 http://cython.org/ largely based on CBS Tools, we hope that the exible framework encourages contribution of new tools, stimulates collaboration, and accelerates progress in the promising eld of highresolution neuroimaging.

Availability of supporting data
The data sets supporting the results of this article are available in the NITRC image repository [30] under https://www.nitrc. org/frs/?group_id=1205.