From 09aad04d68cde5eebb075adeb70b4ff2d59e09b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:27:30 +0200 Subject: [PATCH 1/7] Add short example for transforms to warp function --- skimage/transform/_geometric.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 1ff8e9d5..fda619bf 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -971,6 +971,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, -------- Shift an image to the right: + >>> from skimage.transform import warp >>> from skimage import data >>> image = data.camera() >>> @@ -980,6 +981,12 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, >>> >>> warp(image, shift_right) + Use a geometric transform to warp an image: + + >>> from skimage.transform import SimilarityTransform + >>> tform = SimilarityTransform(scale=0.1, rotation=0.1) + >>> warp(image, tform) + """ # Backward API compatibility if reverse_map is not None: From a569e76a4d2ef804cd74f6776572de12f11f1536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:34:12 +0200 Subject: [PATCH 2/7] Fix parameter description of warp function --- skimage/transform/_geometric.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index fda619bf..57a4fe19 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -946,7 +946,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, Parameters ---------- - image : 2-D array + image : 2-D or 3-D array Input image. inverse_map : transformation object, callable ``xy = f(xy, **kwargs)`` Inverse coordinate map. A function that transforms a (N, 2) array of @@ -955,15 +955,16 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, inverse). map_args : dict, optional Keyword arguments passed to `inverse_map`. - output_shape : tuple (rows, cols) - Shape of the output image generated. - order : int - Order of splines used in interpolation. See - `scipy.ndimage.map_coordinates` for detail. - mode : string - How to handle values outside the image borders. See - `scipy.ndimage.map_coordinates` for detail. - cval : float + output_shape : tuple (rows, cols), optional + Shape of the output image generated. By default the shape of the input + image is preserved. + order : int, optional + The order of the spline interpolation, default is 3. The order has to + be in the range 0-5. + mode : string, optional + Points outside the boundaries of the input are filled according + to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). + cval : float, optional Used in conjunction with mode 'constant', the value outside the image boundaries. From b3c7d67ace9b3caeac3969a88cf62a1a19868fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:38:20 +0200 Subject: [PATCH 3/7] Fix parameter descriptions of warp functions --- skimage/transform/_warps.py | 69 +++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index be7eee12..55aef002 100644 --- a/skimage/transform/_warps.py +++ b/skimage/transform/_warps.py @@ -24,13 +24,13 @@ def resize(image, output_shape, order=1, mode='constant', cval=0.): Other parameters ---------------- - order : int - Order of splines used in interpolation. See - `scipy.ndimage.map_coordinates` for detail. - mode : string - How to handle values outside the image borders. See - `scipy.ndimage.map_coordinates` for detail. - cval : string + order : int, optional + The order of the spline interpolation, default is 3. The order has to + be in the range 0-5. + mode : string, optional + Points outside the boundaries of the input are filled according + to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). + cval : float, optional Used in conjunction with mode 'constant', the value outside the image boundaries. @@ -95,13 +95,13 @@ def rescale(image, scale, order=1, mode='constant', cval=0.): Other parameters ---------------- - order : int - Order of splines used in interpolation. See - `scipy.ndimage.map_coordinates` for detail. - mode : string - How to handle values outside the image borders. See - `scipy.ndimage.map_coordinates` for detail. - cval : string + order : int, optional + The order of the spline interpolation, default is 3. The order has to + be in the range 0-5. + mode : string, optional + Points outside the boundaries of the input are filled according + to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). + cval : float, optional Used in conjunction with mode 'constant', the value outside the image boundaries. @@ -141,13 +141,13 @@ def rotate(image, angle, resize=False, order=1, mode='constant', cval=0.): Other parameters ---------------- - order : int - Order of splines used in interpolation. See - `scipy.ndimage.map_coordinates` for detail. - mode : string - How to handle values outside the image borders. See - `scipy.ndimage.map_coordinates` for detail. - cval : string + order : int, optional + The order of the spline interpolation, default is 3. The order has to + be in the range 0-5. + mode : string, optional + Points outside the boundaries of the input are filled according + to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). + cval : float, optional Used in conjunction with mode 'constant', the value outside the image boundaries. @@ -211,14 +211,14 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0, ---------- image : ndarray Input image. - center : (x,y) tuple or (2,) ndarray + center : (x,y) tuple or (2,) ndarray, optional Center coordinate of transformation. - strength : float + strength : float, optional The amount of swirling applied. - radius : float + radius : float, optional The extent of the swirl in pixels. The effect dies out rapidly beyond `radius`. - rotation : float + rotation : float, optional Additional rotation applied to the image. Returns @@ -228,15 +228,16 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0, Other parameters ---------------- - output_shape : tuple or ndarray - Size of the generated output image. - order : int - Order of splines used in interpolation. See - `scipy.ndimage.map_coordinates` for detail. - mode : string - How to handle values outside the image borders. See - `scipy.ndimage.map_coordinates` for detail. - cval : string + output_shape : tuple (rows, cols), optional + Shape of the output image generated. By default the shape of the input + image is preserved. + order : int, optional + The order of the spline interpolation, default is 3. The order has to + be in the range 0-5. + mode : string, optional + Points outside the boundaries of the input are filled according + to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). + cval : float, optional Used in conjunction with mode 'constant', the value outside the image boundaries. From 071d4bfb68be96f412c0ec881cd6e83c1b2ca1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:45:39 +0200 Subject: [PATCH 4/7] Add examples to doc strings of resize, rotate and rescale functions --- skimage/transform/_warps.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index 55aef002..d00da19b 100644 --- a/skimage/transform/_warps.py +++ b/skimage/transform/_warps.py @@ -34,6 +34,14 @@ def resize(image, output_shape, order=1, mode='constant', cval=0.): Used in conjunction with mode 'constant', the value outside the image boundaries. + Examples + -------- + >>> from skimage import data + >>> from skimage.transform import resize + >>> image = data.camera() + >>> resize(image, (100, 100)).shape + (100, 100) + """ rows, cols = output_shape[0], output_shape[1] @@ -105,6 +113,16 @@ def rescale(image, scale, order=1, mode='constant', cval=0.): Used in conjunction with mode 'constant', the value outside the image boundaries. + Examples + -------- + >>> from skimage import data + >>> from skimage.transform import resize + >>> image = data.camera() + >>> rescale(image, 0.1).shape + (51, 51) + >>> rescale(image, 0.5).shape + (256, 256) + """ try: @@ -151,6 +169,18 @@ def rotate(image, angle, resize=False, order=1, mode='constant', cval=0.): Used in conjunction with mode 'constant', the value outside the image boundaries. + Examples + -------- + >>> from skimage import data + >>> from skimage.transform import rotate + >>> image = data.camera() + >>> rotate(image, 2).shape + (512, 512) + >>> rotate(image, 2, resize=True).shape + (530, 530) + >>> rotate(image, 90, resize=True).shape + (512, 512) + """ rows, cols = image.shape[0], image.shape[1] From 44ca1b9bcdd885bb19b4f758924153678e27dbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:46:36 +0200 Subject: [PATCH 5/7] Fix spelling error --- skimage/transform/_warps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index d00da19b..6eb4eea3 100644 --- a/skimage/transform/_warps.py +++ b/skimage/transform/_warps.py @@ -13,7 +13,7 @@ def resize(image, output_shape, order=1, mode='constant', cval=0.): Input image. output_shape : tuple or ndarray Size of the generated output image `(rows, cols[, dim])`. If `dim` is - not provided, the number of channels are preserved. In case the number + not provided, the number of channels is preserved. In case the number of input channels does not equal the number of output channels a 3-dimensional interpolation is applied. From e6a7238fabb512d08717f40ca449057a77e12724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:50:00 +0200 Subject: [PATCH 6/7] Fix incomplete options for mode of _warp_fast function --- skimage/transform/_warps_cy.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index 968f643a..3ffe9b9b 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -75,7 +75,7 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, int order=1, * 1: Bilinear interpolation (default). * 2: Biquadratic interpolation (default). * 3: Bicubic interpolation. - mode : {'constant', 'reflect', 'wrap'} + mode : {'constant', 'reflect', 'wrap', 'nearest'} How to handle values outside the image borders. cval : string Used in conjunction with mode 'C' (constant), the value From 6c4ed67fe84efae2cbe51c03a4542935b43a8e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 26 May 2013 10:51:42 +0200 Subject: [PATCH 7/7] Wrap lines --- skimage/transform/_geometric.py | 4 ++-- skimage/transform/_warps_cy.pyx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 57a4fe19..a7fdaf6d 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -493,8 +493,8 @@ class SimilarityTransform(ProjectiveTransform): for param in (scale, rotation, translation)) if params and matrix is not None: - raise ValueError("You cannot specify the transformation matrix and " - "the implicit parameters at the same time.") + raise ValueError("You cannot specify the transformation matrix and" + " the implicit parameters at the same time.") elif matrix is not None: if matrix.shape != (3, 3): raise ValueError("Invalid shape of transformation matrix.") diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index 3ffe9b9b..f3a11b45 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -35,8 +35,8 @@ cdef inline void _matrix_transform(double x, double y, double* H, double *x_, y_[0] = yy / zz -def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, int order=1, - mode='constant', double cval=0): +def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, + int order=1, mode='constant', double cval=0): """Projective transformation (homography). Perform a projective transformation (homography) of a