From 9438b96774be506e80de514fc00c82be7c985e67 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 14 Jan 2015 09:59:15 +1100 Subject: [PATCH 1/2] Add default bg_color to label2rgb --- skimage/color/colorlabel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/color/colorlabel.py b/skimage/color/colorlabel.py index c030f849..ecf56ed9 100644 --- a/skimage/color/colorlabel.py +++ b/skimage/color/colorlabel.py @@ -64,7 +64,7 @@ def _match_label_with_color(label, colors, bg_label, bg_color): def label2rgb(label, image=None, colors=None, alpha=0.3, - bg_label=-1, bg_color=None, image_alpha=1, kind='overlay'): + bg_label=-1, bg_color=(0, 0, 0), image_alpha=1, kind='overlay'): """Return an RGB image where color-coded labels are painted over the image. Parameters From eab216884636d1b08b3c63f3511ac56150c7f295 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 14 Jan 2015 10:05:22 +1100 Subject: [PATCH 2/2] Add test to ensure default bg_color in label2rgb --- skimage/color/tests/test_colorlabel.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/skimage/color/tests/test_colorlabel.py b/skimage/color/tests/test_colorlabel.py index 277cec5b..8285a4dc 100644 --- a/skimage/color/tests/test_colorlabel.py +++ b/skimage/color/tests/test_colorlabel.py @@ -91,9 +91,12 @@ def test_leave_labels_alone(): assert_array_equal(labels, labels_saved) def test_avg(): + # label image label_field = np.array([[1, 1, 1, 2], [1, 2, 2, 2], [3, 3, 3, 3]], dtype=np.uint8) + + # color image r = np.array([[1., 1., 0., 0.], [0., 0., 1., 1.], [0., 0., 0., 0.]]) @@ -104,7 +107,8 @@ def test_avg(): [0., 1., 1., 1.], [0., 0., 1., 1.]]) image = np.dstack((r, g, b)) - out = label2rgb(label_field, image, kind='avg') + + # reference label-colored image rout = np.array([[0.5, 0.5, 0.5, 0.5], [0.5, 0.5, 0.5, 0.5], [0. , 0. , 0. , 0. ]]) @@ -115,14 +119,22 @@ def test_avg(): [0. , 1. , 1. , 1. ], [0.5, 0.5, 0.5, 0.5]]) expected_out = np.dstack((rout, gout, bout)) + + # test standard averaging + out = label2rgb(label_field, image, kind='avg') assert_array_equal(out, expected_out) + # test averaging with custom background value out_bg = label2rgb(label_field, image, bg_label=2, bg_color=(0, 0, 0), kind='avg') expected_out_bg = expected_out.copy() expected_out_bg[label_field == 2] = 0 assert_array_equal(out_bg, expected_out_bg) + # test default background color + out_bg = label2rgb(label_field, image, bg_label=2, kind='avg') + assert_array_equal(out_bg, expected_out_bg) + def test_negative_intensity(): labels = np.arange(100).reshape(10, 10)