From 99f905bc547319d58a34c97911c7e27cadf9ac29 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 15 May 2013 17:18:35 +1000 Subject: [PATCH] Always convert image to float in [0, 1] --- skimage/segmentation/slic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/skimage/segmentation/slic.py b/skimage/segmentation/slic.py index d039d5ed..49f51773 100644 --- a/skimage/segmentation/slic.py +++ b/skimage/segmentation/slic.py @@ -50,8 +50,10 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, Notes ----- - The image is optionally smoothed using a Gaussian kernel prior to - segmentation. + If `sigma > 0` as is default, the image is smoothed using a Gaussian kernel + prior to segmentation. + + The image is rescaled to be in [0, 1] prior to processing. References ---------- @@ -72,6 +74,7 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, (multichannel and image.ndim not in [3, 4]) or (multichannel and image.shape[-1] != 3)): ValueError("Only 1- or 3-channel 2- or 3-D images are supported.") + image = img_as_float(image) if not multichannel: image = gray2rgb(image) if image.ndim == 3 and is_rgb(image): @@ -80,7 +83,7 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, if not isinstance(sigma, coll.Iterable): sigma = np.array([sigma, sigma, sigma, 0]) if (sigma > 0).any(): - image = ndimage.gaussian_filter(img_as_float(image), sigma) + image = ndimage.gaussian_filter(image, sigma) if convert2lab: image = rgb2lab(image)