Neuroglancer tools for annotation and alignment of 3D images to the mouse brain atlas
1.2K
#NeUroGlancer Ground-Truth: nuggt
This script uses Neuroglancer to collect cell center ground truth for a 3-d cell segmentation.
Usage:
Compile Neuroglancer according to the directions here and here
Start the static content server:
> npm run dev-server-python
Install nuggt like this:
> git clone https://github.com/chunglabmit/nuggt
> cd nuggt
> pip install -e .
There is a Dockerfile for nuggt. You can build it using
docker build .
It takes a while because of SimpleITK / SimpleElastix
An example of how to run the docker container:
docker run -it --expose 8999 -p 8999:8999/tcp \
--network host -v /path/to/images:/images \
<container-hash>
and from within the docker
nuggt --port 8999 --image /images/myimage.tif --output /images/points.json
Run nuggt like this:
> nuggt --image <image-file> --output <points-json-file> [--min-distance <d>]
where
Commands available in the browser:
nuggt-display uses neuroglancer to display one or more 3-d TIF files along with an optional segmentation and points file.
Run nuggt-display like this:
nuggt-display \
<image-file> <name> <color> \
...
[<image-file> <name> <color>] \
[--segmentation <segmentation>] \
[--points <points>] \
[--ip-address <ip-address>] \
[--port <port>] \
[--static-content-source <static-content-source>]
The triplet of , and can be repeated to display one or more images, each in a different color.
npm run python-dev-server on your machine, "http://localhost:8080"
is likely the correct choice##yea-nay
yea-nay is a tool for quickly separating a list of points into two classes, e.g. true positives and false positives. The user is presented with each point in turn and can either choose "yea" or "nay" (vote yes for "yea" or vote no for "nay"). At the end, the list of points in either class is written out. As-yet undecided points are displayed as yellow dots, "yea" points are displayed as green dots and "nay" points are displayed as red dots.
> yea-nay --help
gives the command-line options for the tool. Inside the browser, the following commands are available:
Align images using Neuroglancer.
nuggt-align is a command-line program that starts two neuroglancer instances, one for a moving image and one for a reference image. The purpose of the program is to establish common points of reference in each image which can be used to warp the moving image onto the reference image.
Run nuggt-align like this:
> nuggt-align --moving-image <moving-image-file> \
--reference-image <reference-image-file> \
--segmentation <segmentation> \
--points <points-file> \
[--no-launch] \
[--ip-address <ip-address>] \
[--port <port>] \
[--static-content-source <static-content-url>] \
[--reference-voxel-size <reference-voxel-size>] \
[--moving-voxel-size <moving-voxel-size]
where:
npm run python-dev-server on your machine, "http://localhost:8080"
is likely the correct choicenuggt-align will print the URLs of the reference viewer and moving viewer on startup. These can be used to launch browser instances for editing.
nuggt-align works by maintaining a list of point annotations for each image in the correspondence-points annotation layer. It maintains one pair of points in the edit annotation layer. These are the points currently being edited. The following commands control the edit process:
sitk-align aligns a moving image to a reference image based on work done by Jae Cho to adapt SimpleElastix / SimpleITK to mouse brain images. The application can both produce an aligned image and, more importantly, it can take a set of reference points, stored in a JSON file and convert these to a point file for nuggt-align.
SimpleElastix has a non-standard installation procedure because it is primarily a C++ application with Python bindings. It should be installed following the super build instructions. One installation method might be to create and activate an Anaconda environment, pip install Nuggt, then run the superbuild in the activated environment. Nuggt has been tested with SimpleElastix git hash 9dfa8cb.
Invoke sitk-align like this:
> sitk-align --moving-file <moving-file> --fixed-file <fixed-file> \
[--fixed-point-file <fixed-point-file>] \
[--alignment-point-file <alignment-point-file>] \
[--aligned-file <aligned-file>]\
[--final-grid-spacing <final-grid-spacing>] \
[--xyz]
where
The make-alignment-file command uses an alignment and a point file, such as generated by nuggt, to make --points file for nuggt-align.
The command line is
make-alignment-file \
--moving-image <moving-image> \
--reference-points <reference-points> \
--output <output-points> \
[--xyz] \
[--reference-key] <reference-key> \
[--moving-key] <moving-key> \
<transform-parameters-file-0> \
[<transform-parameters-file-N>]
where
The keyword parameters are followed by the positional parameters which are a list of TransformParameters.txt files, in the order that they were output by the transformation script, e.g. "TransformParameters.0.txt, TransformParameters.1.txt".
count-points-in-region creates a .csv file listing brain regions and counts of the points that are in them. It does this by warping the input points to the reference segmentation, using an alignment. It finds the segment ID in the reference segmentation for each point and looks up that segment ID in the brain regions CSV input file. You can specify a granularity level for the brain regions file - 7 is the finest grain and 1 is the coarsest.
To run count-points-in-region:
count-points-in-region \
--points <points-file> \
--alignment <alignment-file> \
--reference-segmentation <reference-segmentation-file> \
--brain-regions-csv <brain-regions-file> \
--output <output-file> \
[--level <level>] \
[--xyz] \
[--output-points <output-points-file>]
where
rescale-image-for-alignment takes a stack of images and scales, transposes and rotates it to match an atlas reference file. This command should be used to prepare an image for sitk-align which requires that the input image be oriented similarly to the atlas.
To run:
rescale-image-for-alignment \
--input <input-glob-expression> \
--output <output-path> \
--atlas-file <atlas-file> \
[--x-index <x-index>] \
[--y-index <y-index>] \
[--z-index <z-index>] \
[--flip-x] \
[--flip-y] \
[--flip-z] \
[--clip-x <x-min>,<x-max>] \
[--clip-y <y-min>,<y-max>] \
[--clip-z <z-min>,<z-max>] \
[--thread-count <thread-count>]
where
--input "/path-to/img_*.tiff"rescale-alignment-file takes an alignment file that was generated using a downscaled and possibly flipped and rotated moving file and converts the alignment into one in the original frame of reference. It uses the ratio between the full-size stack's size and the dimensions of the moving file to scale the alignment. If you've transposed the axes, you can correct this using the --x-index, --y-index and --z-index switches. If you've flipped axes, you can correct this using the --flip-x, --flip-y and --flip-z switches. If you clipped any of the axes, you can correct this using --clip-x, --clip-y and --clip-z. The format of these is identical to the format used in rescale-image-for-alignment and the parameters that you used in rescale-image-for-alignment should be duplicated here.
If you need to transpose axes, the --x-index, --y-index and --z-index values refer to the index (0, 1, or 2) of the x, y and z axes in the alignment file and image.
To run:
rescale-alignment-file \
--input <input-alignment-file> \
--alignment-image <alignment-image> \
--stack <image-file-pattern> \
--output <output-alignment-file> \
[--x-index <x-index>] \
[--y-index <y-index>] \
[--z-index <z-index>] \
[--flip-x] \
[--flip-y] \
[--flip-z] \
[--clip-x <xmin>,<xmax>] \
[--clip-y <ymin>,<ymax>] \
[--clip-z <zmin>,<zmax>]
segmentation2stack takes a segmentation in the reference space and transforms it into a TIFF stack of segmentation planes in the sample space using an alignment file.
To run:
segmentation2stack \
--input <input-segmentation> \
--alignment <alignment-file> \
--output <output-folder> \
--stack <stack-expr> \
[--n-cores <n-cores>] \
[--downsample-factor <downsample-factor>] \
[--grid-spacing <grid-spacing>] \
[--silent]
where
One of the purposes of Nuggt is to align a sample image against the mouse atlas reference and collect statistics of counts per region. The following is a possible workflow. There are four stages to the workflow:
Create a list of keypoints for the atlas reference image. The keypoints are evenly-spaced, easily-identifiable points within the reference image that will be used as the initial alignment keypoints in the atlas image. This step only needs to be done once for each atlas reference image and the result can be used for multiple samples. This is done using nuggt to produce the file of keypoints.
Align the sample image to the reference. This involves preparing a downsampled image using rescale-image-for-alignment, running the automatic alignment using sitk-align and then refining this alignment using nuggt-align. Finally, the alignment should be rescaled back to the original image size using rescale-alignment-file.
Identify objects of interest (e.g a particular class of neurons). This can be done through automated means not covered here or can be done manually using nuggt.
Make summary statistics using the atlas. This is done using count-points-in-region.
If you have an atlas autofluorescence file, "autofluorescence_half_sagittal.tif", an annotation file, "annotation_half_sagittal.tif", a listing file giving the correspondences between IDs in the annotation file and brain regions, "AllBrainRegions.csv" and a sample stack, "sample_stack/img_*.tif", the sequence of commands might look like this:
> nuggt --image autofluorescence_half_sagittal.tif \
--output coords_half_sagittal.tif
> # add fiducial points using GUI
> rescale-image-for-alignment --input "sample_stack/img_*.tif" \
--output moving_img.tif \
--atlas-file autofluorescence_half_sagittal.tif
> sitk-align --moving-file moving_img.tif \
--fixed-file autofluorescence_half_sagittal.tif \
--fixed-point-file coords_half_sagittal.json \
--xyz \
--alignment-point-file alignment.json
> nuggt-align --moving-image-file moving_img.tif \
--reference-image-file autofluorescence_half_sagittal.tif \
--points-file alignment.json
> # refine the alignment
> rescale-alignment-file --input alignment.json \
--alignment-image moving_img.tif \
--stack "sample_stack/img_*.tif" \
--output rescaled_alignment.json
> # Perform some analysis that finds points in the original stack
# Assume that the output is "cell_centers.json"
> count-points-in-region --points cell_centers.json \
--alignment rescaled_alignment.json \
--reference-segmentation annotation_half_sagittal.tif \
--brain-regions-csv AllBrainRegions.csv \
--output analysis.csv
The result of the analysis will be summarized in analysis.csv as a table of brain regions and counts of points that fell into each region.
Content type
Image
Digest
Size
2.6 GB
Last updated
about 7 years ago
docker pull chunglabmit/nuggt