From 469ad7e77e03e0822ff61e3c5d6fda61d75a7d4c Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 19 Nov 2021 11:56:38 +0800 Subject: [PATCH 1/3] [DLMED] enhance doc-string Signed-off-by: Nic Ma --- monai/visualize/utils.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/monai/visualize/utils.py b/monai/visualize/utils.py index 29def9d0ef..1fbff63784 100644 --- a/monai/visualize/utils.py +++ b/monai/visualize/utils.py @@ -131,9 +131,22 @@ def matshow3d( def blend_images( image: NdarrayOrTensor, label: NdarrayOrTensor, alpha: float = 0.5, cmap: str = "hsv", rescale_arrays: bool = True ): - """Blend two images. Both should have the shape CHW[D]. + """ + Blend a image and a label. Both should have the shape CHW[D]. The image may have C==1 or 3 channels (greyscale or RGB). - The label is expected to have C==1.""" + The label is expected to have C==1. + + Args: + image: the input image to blend with label data. + label: the input label to blend with image data. + alpha: when blending image and label, `alpha` is weight for the image region mapping to `label != 0`, + and `1 - alpha` is weight for the label region that `label != 0`. + cmap: specify colormap in the matplotlib, for more details, please refer to: + https://matplotlib.org/2.0.2/users/colormaps.html. + rescale_arrays: whether to rescale the array to [0, 1] first. + + """ + if label.shape[0] != 1: raise ValueError("Label should have 1 channel") if image.shape[0] not in (1, 3): From 07aa5513f39a82cf36cd7969948212dadab60190 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 19 Nov 2021 12:18:01 +0800 Subject: [PATCH 2/3] [DLMED] update according to comments Signed-off-by: Nic Ma --- monai/visualize/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/visualize/utils.py b/monai/visualize/utils.py index 1fbff63784..60fde75cde 100644 --- a/monai/visualize/utils.py +++ b/monai/visualize/utils.py @@ -139,11 +139,11 @@ def blend_images( Args: image: the input image to blend with label data. label: the input label to blend with image data. - alpha: when blending image and label, `alpha` is weight for the image region mapping to `label != 0`, - and `1 - alpha` is weight for the label region that `label != 0`. + alpha: when blending image and label, `alpha` is the weight for the image region mapping to `label != 0`, + and `1 - alpha` is the weight for the label region that `label != 0`. cmap: specify colormap in the matplotlib, for more details, please refer to: https://matplotlib.org/2.0.2/users/colormaps.html. - rescale_arrays: whether to rescale the array to [0, 1] first. + rescale_arrays: whether to rescale the array to [0, 1] first, default to `True`. """ From 3a10fcf2f5e14ab39c504cd3b3d0ca45b681b155 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 19 Nov 2021 16:46:21 +0800 Subject: [PATCH 3/3] [DLMED] add default Signed-off-by: Nic Ma --- monai/visualize/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/visualize/utils.py b/monai/visualize/utils.py index 60fde75cde..0a985c0c21 100644 --- a/monai/visualize/utils.py +++ b/monai/visualize/utils.py @@ -140,8 +140,8 @@ def blend_images( image: the input image to blend with label data. label: the input label to blend with image data. alpha: when blending image and label, `alpha` is the weight for the image region mapping to `label != 0`, - and `1 - alpha` is the weight for the label region that `label != 0`. - cmap: specify colormap in the matplotlib, for more details, please refer to: + and `1 - alpha` is the weight for the label region that `label != 0`, default to `0.5`. + cmap: specify colormap in the matplotlib, default to `hsv`, for more details, please refer to: https://matplotlib.org/2.0.2/users/colormaps.html. rescale_arrays: whether to rescale the array to [0, 1] first, default to `True`.