Linked MRI#
Linked MRI shows the subject’s own T1-weighted scan in three orthogonal planes around one crosshair shared with the 3D cut. The planes are resampled in the browser from the lossless orig.mgz and aseg.mgz grids of the FreeSurfer reconstruction, with a contrast window measured per subject and an optional segmentation overlay. Nothing is normalised or sharpened, so grey is proportional to T1 signal; the scan is 1 mm and not intensity-normalised across subjects. On the MNI template the planes show the template’s own T1, an average of 152 people’s scans.
Fig. 3 | Three planes resampled around one crosshair, without and with the segmentation overlay. a, Linked MRI opened with M on a coronal cut at y = −10 mm: sagittal (seen from the right), coronal (from the front, radiological) and axial (from above, neurological) planes through the crosshair at (0, −10, 0) mm surface RAS, which the readout names Brainstem (aseg label 16); published window (level 94, width 188). b, The same planes with Segmentation overlay: each labelled pixel is \(0.55 \times\) grey \(+ 0.45 \times\) its FreeSurfer label colour, unlabelled pixels keep their grey. Subject CDMD sub_013; 256 mm field of view sampled at 512 × 512 pixels per plane.#
Data#
File |
Contents |
|---|---|
|
|
|
|
|
|
|
FA on the diffusion T1’s grid, placed in surface RAS by |
Each volume record carries shape, dtype, order: "F", compression: "gzip", byte_length, sha256 (file), decoded_sha256 (payload), voxel_to_surface_ras_mm and voxel_spacing_mm; the cropped record adds source_shape and crop_corner_voxel. display holds field_of_view_mm = 256, texture_size = 512 and the measured window, level 94 and width 188 on CDMD. The T1 is orig.mgz, conformed to \(256^3\) at 1 mm but not intensity-normalised.
Method#
Volume export#
export_volumesloadedmri/orig.mgzandmri/aseg.mgzand required equal shape, scanner affine and tkregister matrix (validate_same_grid); only a conformed volume’s own tkregister matrix is surface RAS.The T1 was written whole as
uint8; the segmentation as<u2, cropped to its non-zero voxels with the affine shifted by the crop corner.encode_arrayrefuses non-finite data, out-of-range values and any change under the cast. Payloads are Fortran order (x fastest), gzipped withcompresslevel=9andmtime=0, so the bytes are reproducible.Each label present was named and coloured from the FreeSurfer lookup table.
Default window#
The window is measured from the T1 inside every non-zero aseg voxel (display_window):
so the window runs from 0 to an even ceiling \(h\). The floor stays at 0 so displayed grey is proportional to T1 signal and surfaces, cut faces and planes show the same tissue at the same grey. The window is per subject because orig.mgz carries no common scale: white-matter medians were 144 in CDMD and 221 in the subject Planum published before it (DIPY’s SNAIL example dataset, since retired). On the published files \(h\) is 188 for CDMD and 256 for the MNI template, whose averaged T1 reaches the top of orig.mgz’s 8-bit range. An empty segmentation or \(h \le 0\) fails the build.
Plane resampling#
sampleSlice samples one plane as a \(512 \times 512\) image over a 256 mm square, one sample at each pixel centre \(\mathbf{p}\), and keeps all that the window does not change; windowSlice draws those samples through the window without reading a volume again:
T1.
Volume.linear, trilinear over the eight surrounding voxels and 0 outside the grid, kept as a double and mapped through level \(c\) and width \(w\): $\(g = \operatorname{clamp}\bigl((T_1(\mathbf{p}) - c + w/2)\,255/w,\ 0,\ 255\bigr).\)$Label.
Volume.label, the label with the largest summed trilinear weight over the eight voxels (the ANTs genericLabel rule): exact at voxel centres and never a label absent from the eight. It is the CPU twin of the cut faces’LABEL_AT(sections and cuts).Overlay. A labelled pixel is \(0.55\,g + 0.45\,\text{colour}\). With a segmentation agreement shown, one structure is inked instead by category: both segmentations (236, 236, 236), aseg only (235, 70, 210), NextBrain only (255, 150, 30).
Paint. A pixel whose label on the cut atlas’s grid is painted takes the paint’s colour, whatever the window.
Map. The reader’s overlay map is drawn over the result at its opacity, as the cut faces draw it.
On the tracts’ own anatomy, FA where one is published (CDMD only; viridis over 0–1, sampled at each pixel centre) is then blended over the pixels at FA opacity, and the drawn tracts within 2 mm of the plane (TRACT_SLAB_MM), clipped to that slab and laid flat on it, are drawn one pixel wide in their direction colours (tracts). Every pixel is drawn opaque, so voxels no label covers keep their T1 grey.
Plane frames#
Each plane is seen from the side the stage faces the cut (the other side when reversed), with screen-right \(\mathbf{u} = \mathbf{v} \times \mathbf{e}\) for screen-up \(\mathbf{v}\) and direction to the eye \(\mathbf{e}\) (stagedFrame). Edge letters follow from \(\mathbf{u}\) and \(\mathbf{v}\); an axial or coronal panel is labelled neurological when L is at its left edge and radiological when R is. A click inverts the frame to a point (pointOnPlane); the crosshair is clamped to ±128 mm.
Display#
Linked MRI opens from a region’s detail, a function’s or deficit’s profile, the section bar, the Tracts tab’s MRI with tracts or the M key. A function’s opens at the anchor of its strongest area, a deficit’s at its first finding’s first region (the chosen finding’s, if one is); the overview of all functions opens where the crosshair is. The crosshair is the cut’s: a click on a plane moves the crosshair there, cuts the 3D brain on that plane through the point and selects the smallest shown solid that contains it (regionAt); a click on the 3D brain moves the crosshair to the picked surface point. The wheel moves a plane 1 mm a notch; each plane has a 1 mm position slider, whose arrow keys move the crosshair 1 mm. Window (width 10–256) and Level (0–255) apply to the planes and to T1 surface colour alike. The crosshair is drawn at screen resolution in #4fb6e0 over a #0e1116 ring; only a plane whose frame, overlay, agreement, paint, map or tracts changed is resampled, and Window, Level and FA opacity draw it again from the samples it kept (mpr-plane-cache.ts). While the model shows any paint, each voxel whose label on the cut atlas’s own grid (the surface atlas’s, which a paint keeps on the cut) is painted takes that colour, opaque over the scan, as the cut faces show it; that grid downloads the first time a paint needs it. The readout gives the RAS position, the region the current cut labels name, the aseg structure and label number, the agreement category while one is shown, the reader’s map value where it has one and FA while it is shown, and is announced after 250 ms at rest. Reset display returns Window and Level to the published window, clears Segmentation overlay and sets FA opacity to 0. With a segmentation agreement shown, a legend names the structure (Agreement: <structure>) and its three categories, the overlay box is disabled, and Hide agreement returns to the segmentation. On the tracts’ own anatomy the planes draw the tracts the stage draws and offer FA opacity (0–100%, step 5%, default 0); FA downloads the first time it leaves 0, and a note says what the tracts and FA are. Save PNG writes the 512-pixel plane with crosshair, edge letters, convention and offset as <subject>-<plane>-<offset>mm.png.
On a desktop or tablet the planes dock beside the stage (column 240 px to the width that leaves the stage 360 px; 24 px per arrow key; a double click on the edge restores the default width); on a phone or a full-screen stage they open as a modal dialog. URL key: mri=<level>,<width>, written only when the window differs from the published one and accepted for level 0–255 and width 1–256.
Validation#
Test |
Criterion |
Result |
|---|---|---|
Round trip ( |
Both volumes decode, match both checksums, and placed by their affines equal |
passes |
Grid registration ( |
A differing shape, scanner affine or tkregister matrix fails before writing |
passes |
Window ceiling ( |
Fewer than 0.5% of segmented T1 voxels at or above the ceiling |
passes |
Window floor ( |
\(\text{level} - \text{width}/2 = 0\) |
passes |
Per-subject window ( |
CDMD and |
passes |
Sampling ( |
Grey is the windowed T1 clamped to 0–255; overlay blends 0.55/0.45; labels never invented; voxel centres keep their label; the reader’s map is drawn by its opacity where it passes its threshold |
passes |
GPU–CPU labels ( |
|
passes |
Kept samples ( |
A new window draws the pixels sampling through it draws; Window, Level and FA opacity redraw each plane without reading a volume, FA or the tracts again |
passes |
Tracts and FA ( |
Segments are cut where they leave the 2 mm slab and laid flat on the plane; FA downloads once its opacity leaves zero and joins the readout; another subject’s tracts are not drawn and FA is not offered; Reset display returns FA opacity to zero |
passes |
Paint ( |
A painted label is drawn in its colour over the scan; the label grid loads only once the planes have, and a failed load is reported once |
passes |
Frames and clicks ( |
A click’s point marks the crosshair at that click; the coronal panel faced from the front puts the subject’s right on the left |
passes |
Limitations#
One individual’s 1 mm MRI and segmentation, not the viewer’s anatomy.
Trilinear interpolation does not increase source resolution.
The scan is not intensity-normalised; grey levels do not compare across subjects.
The overlay is aseg, whatever atlas the stage shows; cortical surface atlases are not extended into the volume. A paint is drawn by the cut atlas’s own label grid instead.
volumes.jsondescribes the segmentation as sampled by nearest neighbour; the viewer samples it by largest trilinear weight.Hidden or isolated regions do not change the planes.
Agreement is not accuracy: neither segmentation is the reference.
Code availability#
Code |
|
Configuration |
|
Tests |
|
uv run python -m brain_model.labels.volumes
uv run python -m brain_model.validate --anatomy cdmd
uv run pytest tests/test_volumes.py
npm test --prefix web -- slices sections native-geometry
npm run test:browser --prefix web -- MprDialog label-sampling
Figure state (Fig. 1a, then M): https://planumatlas.com/#anatomy=cdmd&atlas=destrieux&colors=atlas&cut=coronal&pos=-10