This repository contains a pipeline for registering Imaris .ims brain images to a BrainGlobe atlas, processing the resulting masks and uploading them to Imaris as surfaces. The pipeline is divided into 3 main parts, that can be used separately:
- Raw .ims data downscaling (ImageJ macro:
00a_rescaleMacroBatch.ijm/00b_rescaleMacro.ijm), followed by brain atlas registration in BrainGlobe (not automated) - Processing of the brain region mask (Python script:
01_mask_processing_pipeline.py) - adjusting the level of details, discarding small disconnected components and converting the mask from 32-bit to 16-bit image. - Importing the mask to Imaris (built-in Imaris function) followed by importing corresponding brain region and IDs (custom Imaris XTension:
XT_ImportBrainRegionIdentificators.m).
- ImageJ / Fiji (Schindelin et al., 2012) - for part 1
- Miniconda - for part 1 and 2
- Python 3.12 - for part 1 and 2
- BrainGlobe (Claudi et al., 2021; Tyson et al., 2022) - for part 1 and 2
- Imaris (with XTension support) - for part 3
1. Set up the Python BrainGlobe environment (required for registration and subsequent mask processing)
conda create -n brainglobe_env python=3.12
conda activate brainglobe_env
pip install brainglobeFor more detailed description, follow information on the BrainGlobe webpage: https://brainglobe.info/documentation/index.html
2. Install the provided Imaris XTension (required for import of brain region names and IDs to Imaris)
Copy the XT_ImportBrainRegionIdentificators.py to your Imaris XTensions folder, such as:
C:\Users\<YourUsername>\Documents\Imaris\XTensions
(Path to Imaris extension folder can be set in Imaris Preferences.)
Restart Imaris.
Rescaling is included for easier handling of large datasets. (such as in case of lightsheet data)
- Open the macro script in Fiji. If you want to process more files at once, open the batch script option (
00a_rescaleMacro.ijm), otherwise, use the second option that will process a single image (00b_rescaleMacro.ijm) - In the macro, adjust parameters if needed.
- Run the macro.
- Open Napari and drag the
.tiffimage (use 'napari builtins' reader, if asked). - Download the atlas if needed via brainrender → Manage atlas versions
- Open brainreg plugin
- Configure:
- Atlas:
perens_lsmf_mouse_20umsuitable for lightsheet data, or other selected - Orientation: Use Check Orientation tool (docs)
- Region: Full brain or left/right hemisphere
- Voxel size: ~20 µm (check in Fiji: Image → Properties)
- Save original orientation: Check this option
- Output directory: Set accordingly
- Keep other settings default unless optimizing
- Atlas:
- Click Run
- If registration misaligned, try changing Smoothing sigma to
0, and optimize other parameters
The processing adjusts the level of detail, discards small regions and converts the mask to 16-bit, which is needed for loading to Imaris.
- Open
01_mask_processing_pipeline.pyin any text or code editor. - If needed, adjust parameters, such as the list of regions to flatten.
- Run the script.
You can run the script from the Anaconda Prompt as follows:
-
Open the Anaconda Prompt.
-
Activate the BrainGlobe environment:
conda activate brainglobe_env
-
Navigate to the folder containing the script:
cd path/to/your/script -
Run the script:
python mask_processing_pipeline.py
- When prompted, select the original mask path.
. The script will output the processed mask (adjusted_mask.tiff) in the same folder.
IMPORTANT: If you want to directly import masks from BrainGlobe to Imaris without using the script from part 2, make sure to convert the mask to 16-bit before using hte Import Segmentation/Label function. If you attempt importing a 32-bit mask, Imaris seems to get stuck.
-
Open original
.imsfile -
Go to:
Import → Import Segmentation/Labeland select the adjusted mask → This creates new surfaces
IMPORTANT: The mask cannot be 32-bit, otherwise the loading gets stuck.
-
Select the surfaces object, in XTension tab → Run Brain region identificators import
-
When prompted, provide:
adjusted_mask.tif(the adjusted mask that was loaded in the previous step)used_region_ids.csv(a CSV file with two columns:region_idfor the numeric region identifiers andregion_namefor the corresponding anatomical names)
-
Wait for label import to finish (may take a few minutes)
In case of big datasets, the import of identifiers can get stuck. In that case, you can use a workaround. Instead of opening the original .ims file, you can use the downsampled .tiff file directly:
- Open the downsampled
.tifffile in Imaris.- It will be automatically converted to
.imsformat.
- It will be automatically converted to
- Use the same mask import procedure as described above:
Import → Import Segmentation/Label- This creates new surfaces.
- Run the Brain region identificators import XTension on the surfaces.
- When prompted, provide:
adjusted_mask.tifused_region_ids.csv
- Once the labels are imported, export the scene via:
File → Export Scene - Open the original
.imsfile. - Import the previously exported scene using:
File → Import Scene → Add to existing objects - Important: Before importing, make sure the voxel origin of the image (minimum µm) is set to 0 in all dimensions. Otherwise, the imported surfaces may be shifted.
This approach is useful if you want to work with a smaller image first and transfer results back to the full-resolution dataset.
Iva Švecová, Institute of Experimental Medicine (iva.svecova@iem.cas.cz)
If you use this code, please cite the repository using the following DOI: