Skip to content

Commit d55e239

Browse files
committed
ENH: Allow plotting of image rotated to cardinal axes
1 parent bd6cd6f commit d55e239

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

niworkflows/interfaces/reportlets/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class RegistrationRC(reporting.ReportCapableInterface):
5252
_fixed_image_label = "fixed"
5353
_moving_image_label = "moving"
5454
_contour = None
55+
_rotate_to_canonical = False
5556

5657
def _generate_report(self):
5758
"""Generate the visual report."""
@@ -96,6 +97,7 @@ def _generate_report(self):
9697
label=self._fixed_image_label,
9798
contour=contour_nii,
9899
compress=self.inputs.compress_report,
100+
rotate_to_canonical=self._rotate_to_canonical,
99101
),
100102
plot_registration(
101103
moving_image_nii,
@@ -105,6 +107,7 @@ def _generate_report(self):
105107
label=self._moving_image_label,
106108
contour=contour_nii,
107109
compress=self.inputs.compress_report,
110+
rotate_to_canonical=self._rotate_to_canonical,
108111
),
109112
out_file=self._out_report,
110113
)

niworkflows/interfaces/reportlets/registration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ class _SimpleBeforeAfterInputSpecRPT(nrb._SVGReportCapableInputSpec):
351351
wm_seg = File(desc="reference white matter segmentation mask")
352352
before_label = traits.Str("before", usedefault=True)
353353
after_label = traits.Str("after", usedefault=True)
354+
rotate_to_canonical = traits.Bool(
355+
False, usedefault=True, desc="rotate image(s) to cardinal axes"
356+
)
354357

355358

356359
class SimpleBeforeAfterRPT(nrb.RegistrationRC, nrb.ReportingInterface):
@@ -363,6 +366,7 @@ def _post_run_hook(self, runtime):
363366
self._fixed_image = self.inputs.after
364367
self._moving_image = self.inputs.before
365368
self._contour = self.inputs.wm_seg if isdefined(self.inputs.wm_seg) else None
369+
self._rotate_to_canonical = self.inputs.rotate_to_canonical
366370
NIWORKFLOWS_LOG.info(
367371
"Report - setting before (%s) and after (%s) images",
368372
self._fixed_image,

niworkflows/viz/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def plot_registration(
324324
label=None,
325325
contour=None,
326326
compress="auto",
327+
rotate_to_canonical=False,
327328
):
328329
"""
329330
Plots the foreground and background views
@@ -351,6 +352,15 @@ def plot_registration(
351352
white = nlimage.new_img_like(contour, contour_data == 2)
352353
pial = nlimage.new_img_like(contour, contour_data >= 2)
353354

355+
if rotate_to_canonical:
356+
canonical_r = rotation2canonical(anat_nii)
357+
anat_nii = rotate_affine(anat_nii, rot=canonical_r)
358+
if ribbon:
359+
white = rotate_affine(white, rot=canonical_r)
360+
pial = rotate_affine(pial, rot=canonical_r)
361+
if contour:
362+
contour = rotate_affine(contour, rot=canonical_r)
363+
354364
# Plot each cut axis
355365
for i, mode in enumerate(list(order)):
356366
plot_params["display_mode"] = mode

0 commit comments

Comments
 (0)