-
Notifications
You must be signed in to change notification settings - Fork 15
/
notebook.py
62 lines (57 loc) · 1.83 KB
/
notebook.py
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
"""Visualization component for Jupyter Notebooks."""
from pathlib import Path
import numpy as np
import nibabel as nb
from .utils import compose_view, plot_registration, cuts_from_bbox
def display(
fixed_image,
moving_image,
contour=None,
cuts=None,
fixed_label="F",
moving_label="M",
):
"""Plot the flickering panels to show a registration process."""
from IPython.display import SVG, display as _disp
if isinstance(fixed_image, (str, Path)):
fixed_image = nb.load(str(fixed_image))
if isinstance(moving_image, (str, Path)):
moving_image = nb.load(str(moving_image))
if cuts is None:
n_cuts = 7
if contour is not None:
if isinstance(contour, (str, Path)):
contour = nb.load(str(contour))
cuts = cuts_from_bbox(contour, cuts=n_cuts)
else:
hdr = fixed_image.header.copy()
hdr.set_data_dtype("uint8")
mask_nii = nb.Nifti1Image(
np.ones(fixed_image.shape, dtype="uint8"), fixed_image.affine, hdr
)
cuts = cuts_from_bbox(mask_nii, cuts=n_cuts)
# Call composer
_disp(
SVG(
compose_view(
plot_registration(
fixed_image,
"fixed-image",
estimate_brightness=True,
cuts=cuts,
label=fixed_label,
contour=contour,
compress=False,
),
plot_registration(
moving_image,
"moving-image",
estimate_brightness=True,
cuts=cuts,
label=moving_label,
contour=contour,
compress=False,
),
)
)
)