diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 1ff8e9d5..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.") @@ -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. @@ -971,6 +972,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 +982,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: diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index be7eee12..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. @@ -24,16 +24,24 @@ 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. + 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] @@ -95,16 +103,26 @@ 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. + 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: @@ -141,16 +159,28 @@ 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. + 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] @@ -211,14 +241,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 +258,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. diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index 968f643a..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 @@ -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