petersaj / AP_histology

Histology processing
64 stars 22 forks source link

Toolbox for aliging histology images to the Allen CCF mouse atlas.

A video demonstration of this toolbox is available here (note - old interface): https://www.youtube.com/watch?v=HKm_G17Wc6g

Inspiration from SHARP-Track by Philip Shamash (https://www.biorxiv.org/content/10.1101/447995v1).

Installation

*(note on where these files came from: they are a re-formatted version of the original atlas, which has been processed with this script)

Histology preprocessing

Toolbox menu

Open the toolbox menu with:

AP_histology

This is the menu for to run all toolbox functions.

image

The menu functions are described below.

File selection

Set the location of the raw images and save path

Image preprocessing

Create slice images

1) Downsample image sizes (if desired) 2) Set white balance and color for each channel 3) Extract slices into individual images (if not already)

In the initial dialog box, select the image downsampling factor (e.g. 2 reduces image size to 1/2) and whether images are individual slices (1 = slices, 0 = not slices, e.g. slides)

A montage of images will be shown for each channel, user selects white balance and color: image

To create individual slice images from slide imges:

Rotate & center slices

Draw reference line (e.g. the midline): image

These reference lines will used to centered and rotate the slice images, which are then saved.

Re-order slices

Images can be re-ordered (click to select order)

Flip slices

Images can be flipped (left/right or up/down)

Atlas alignment

Choose histology atlas slices

This function is to match histology slices to their corresponding CCF slices. The left plot is the histology slices (scrollable by 1/2), the right plot is the 3D CCF atlas which is rotatable with the arrow keys and scrollable in/out of the plane with the mouse wheel. Typical use would be:

Auto-align histology/atlas slices

This function auto-aligns each corresponding histology and CCF slice by slice outline. Alignments which need manual correction can be fixed in the next step. image

Manual-align histology/atlas slices

If the auto-alignment didn't work on some slices, they can be manually fixed with this function. Placing > 3 corresponding points on the histology and CCF slices creates a new alignment using those control points, and 'Escape' saves and quits.

From auto-alignment: image

After manual control-point alignment: image

Annotation

Neuropixels probes

Get trajectory of dyed probe in CCF coordinates and areas.

Draw lines on slices with visible tract marks corresponding to the probe (select the relevant probe by number, e.g. '1' to draw a line for probe 1). Lines for a given probe can be (and usually are) drawn across multiple slices. test image

The final probe trajectory will be a line of best fit through all marked points, and brain areas will be saved along that trajectory. NOTE: it is unusual that the exact end of the probe can be visualized and accurately established from histology alone, so this step saves the entire trajectory and the next step aligns it to electrophysiology. test image

View

View aligned histology

Display the histology slices with overlaid boundaries, hover over region to display name

Major change log

2024-02-16 - Split re-order/flip GUIs: re-ordering is now a simpler click interface 2023-11-02 - Created menu GUI for easier interfacing re-structured/improve much of the code, improved auto-align