Skip to content

Commit 127d4d0

Browse files
committed
ENH: add checkerboard paramter to compare_images
1 parent f3103cf commit 127d4d0

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

itkwidgets/viewer.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def set_image_volume_sample_distance(self, distance: float):
275275
def set_image_volume_scattering_blend(self, scattering_blend: float):
276276
self.queue_request('setImageVolumeScatteringBlend', scattering_blend)
277277

278-
def compare_images(self, fixed_image: Union[str, Image], moving_image: Union[str, Image], method: str = 'checkerboard', pattern: Tuple[int, int, int] = [4, 4, 4], swap_image_order: bool = False, image_mix: float = .5):
278+
def compare_images(self, fixed_image: Union[str, Image], moving_image: Union[str, Image], method: str = None, image_mix: float = None, checkerboard: bool = None, pattern: Tuple[int, int, int] = None, swap_image_order: bool = None):
279279
# image args may be image name or image object
280280
fixed_name = 'Fixed'
281281
if isinstance(fixed_image, str):
@@ -287,7 +287,18 @@ def compare_images(self, fixed_image: Union[str, Image], moving_image: Union[str
287287
moving_name = moving_image
288288
else:
289289
self.set_image(moving_image, moving_name)
290-
options = { 'method': method, 'pattern': pattern, 'swapImageOrder': swap_image_order, 'imageMix': image_mix }
290+
options = {}
291+
# if None let viewer use defaults or last value.
292+
if method is not None:
293+
options['method'] = method
294+
if image_mix is not None:
295+
options['imageMix'] = image_mix
296+
if checkerboard is not None:
297+
options['checkerboard'] = checkerboard
298+
if pattern is not None:
299+
options['pattern'] = pattern
300+
if swap_image_order is not None:
301+
options['swapImageOrder'] = swap_image_order
291302
self.queue_request('compareImages', fixed_name, moving_name, options)
292303

293304
def set_label_image(self, label_image: Image):
@@ -470,7 +481,7 @@ def view(data=None, **kwargs):
470481
def compare_images(*args, **kwargs):
471482
"""Fuse 2 images with a checkerboard filter or as a 2 component image.
472483
473-
The moving image is re-sampled to the fixed image space.
484+
The moving image is re-sampled to the fixed image space. Set a keyword argument to None to use defaults based on method.
474485
475486
Parameters
476487
----------
@@ -480,24 +491,28 @@ def compare_images(*args, **kwargs):
480491
moving_image: array_like, itk.Image, or vtk.vtkImageData
481492
Image is re-sampled to the fixed_image.
482493
483-
method: string, default: 'checkerboard', possible values: 'cyan-magenta', 'blend', 'checkerboard'
484-
checkerboard picks pixels from the fixed and moving image to create a
494+
method: string, default: None, possible values: 'cyan-magenta', 'blend', 'checkerboard'
495+
checkerboard method picks pixels from the fixed and moving image to create a
485496
checkerboard pattern.
486497
cyan-magenta method puts the fixed image on component 0, moving image on component 1
487498
and changes the color map for fixed image to cyan, moving image to magenta.
488499
blend method puts the fixed image on component 0, moving image on component 1
489500
and changes the color maps for both to grayscale.
490501
491-
pattern: Tuple[int, int, int], default: [4, 4, 4]
502+
imageMix: float, default: None
503+
Changes the percent contribution the fixed vs moving image makes to the
504+
render by modifying the opacity transfer function. Value of 1 means max opacity for
505+
moving image, 0 for fixed image. Only active when method is cyan-magenta or blend.
506+
507+
checkerboard: bool, default: None
508+
Forces checkerboard pattern for cyan-magenta and blend methods.
509+
510+
pattern: Tuple[int, int, int], default: None
492511
An array with the number of checkerboard boxes for each dimension.
493512
494-
swap_image_order: bool, default: false
513+
swap_image_order: bool, default: None
495514
Reverses which image is sampled for each checkerboard box.
496515
497-
imageMix: float, default: 0.5
498-
Changes the percent contribution the fixed vs moving image makes to the
499-
render by modifying the opacity transfer function. Value of 1 means max opacity for
500-
moving image, 0 for fixed image. Only active when method is cyan-magenta or blend.
501516
"""
502517
viewer = view()
503518
viewer.compare_images(*args, **kwargs)

0 commit comments

Comments
 (0)