From a17a1395c385605fcac506fcd0dc2d0e2c2a09e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 28 Sep 2013 14:23:15 +0200 Subject: [PATCH 1/2] Fix doc string of warp functions --- skimage/transform/_geometric.py | 9 +++++++-- skimage/transform/_warps_cy.pyx | 20 ++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 6117008a..23359a93 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -962,8 +962,13 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, 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. + The order of interpolation. The order has to be in the range 0-5: + * 0: Nearest-neighbor + * 1: Bi-linear (default) + * 2: Bi-quadratic + * 3: Bi-cubic + * 4: Bi-quartic + * 5: Bi-quintic mode : string, optional Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index 5dc2ffd0..b3136c22 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -40,22 +40,18 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, """Projective transformation (homography). Perform a projective transformation (homography) of a - floating point image, using bi-linear interpolation. + floating point image, using interpolation. For each pixel, given its homogeneous coordinate :math:`\mathbf{x} = [x, y, 1]^T`, its target position is calculated by multiplying with the given matrix, :math:`H`, to give :math:`H \mathbf{x}`. - E.g., to rotate by theta degrees clockwise, the matrix should be - - :: + E.g., to rotate by theta degrees clockwise, the matrix should be:: [[cos(theta) -sin(theta) 0] [sin(theta) cos(theta) 0] [0 0 1]] - or, to translate x by 10 and y by 20, - - :: + or, to translate x by 10 and y by 20:: [[1 0 10] [0 1 20] @@ -69,12 +65,12 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, Transformation matrix H that defines the homography. output_shape : tuple (rows, cols), optional Shape of the output image generated (default None). - order : {0, 1}, optional + order : {0, 1, 2, 3}, optional Order of interpolation:: - * 0: Nearest-neighbour interpolation. - * 1: Bilinear interpolation (default). - * 2: Biquadratic interpolation. - * 3: Bicubic interpolation. + * 0: Nearest-neighbor + * 1: Bi-linear (default) + * 2: Bi-quadratic + * 3: Bi-cubic mode : {'constant', 'reflect', 'wrap', 'nearest'}, optional How to handle values outside the image borders (default is constant). cval : string, optional (default 0) From c01e7c9b105165967c1c200307011c202659516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 28 Sep 2013 14:39:40 +0200 Subject: [PATCH 2/2] Fix various doc strings using the warp function --- skimage/transform/_warps.py | 16 +++++++-------- skimage/transform/pyramids.py | 38 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index d8da73d5..64b129dd 100644 --- a/skimage/transform/_warps.py +++ b/skimage/transform/_warps.py @@ -32,8 +32,8 @@ def resize(image, output_shape, order=1, mode='constant', cval=0.): Other parameters ---------------- order : int, optional - The order of the spline interpolation, default is 3. The order has to - be in the range 0-5. + The order of the spline interpolation, default is 1. The order has to + be in the range 0-5. See `skimage.transform.warp` for detail. mode : string, optional Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). @@ -116,8 +116,8 @@ def rescale(image, scale, order=1, mode='constant', cval=0.): Other parameters ---------------- order : int, optional - The order of the spline interpolation, default is 3. The order has to - be in the range 0-5. + The order of the spline interpolation, default is 1. The order has to + be in the range 0-5. See `skimage.transform.warp` for detail. mode : string, optional Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). @@ -172,8 +172,8 @@ def rotate(image, angle, resize=False, order=1, mode='constant', cval=0.): Other parameters ---------------- order : int, optional - The order of the spline interpolation, default is 3. The order has to - be in the range 0-5. + The order of the spline interpolation, default is 1. The order has to + be in the range 0-5. See `skimage.transform.warp` for detail. mode : string, optional Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). @@ -315,8 +315,8 @@ def swirl(image, center=None, strength=1, radius=100, rotation=0, 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. + The order of the spline interpolation, default is 1. The order has to + be in the range 0-5. See `skimage.transform.warp` for detail. mode : string, optional Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'reflect' or 'wrap'). diff --git a/skimage/transform/pyramids.py b/skimage/transform/pyramids.py index 19001de8..a68b7a70 100644 --- a/skimage/transform/pyramids.py +++ b/skimage/transform/pyramids.py @@ -6,11 +6,11 @@ from skimage.util import img_as_float def _smooth(image, sigma, mode, cval): - """Return image with each channel smoothed by the gaussian filter.""" + """Return image with each channel smoothed by the Gaussian filter.""" smoothed = np.empty(image.shape, dtype=np.double) - if image.ndim == 3: # apply gaussian filter to all dimensions independently + if image.ndim == 3: # apply Gaussian filter to all dimensions independently for dim in range(image.shape[2]): ndimage.gaussian_filter(image[..., dim], sigma, output=smoothed[..., dim], @@ -38,13 +38,13 @@ def pyramid_reduce(image, downscale=2, sigma=None, order=1, downscale : float, optional Downscale factor. sigma : float, optional - Sigma for gaussian filter. Default is `2 * downscale / 6.0` which + Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which corresponds to a filter mask twice the size of the scale factor that - covers more than 99% of the gaussian distribution. + covers more than 99% of the Gaussian distribution. order : int, optional Order of splines used in interpolation of downsampling. See - `scipy.ndimage.map_coordinates` for detail. - mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional + `skimage.transform.warp` for detail. + mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. cval : float, optional @@ -92,13 +92,13 @@ def pyramid_expand(image, upscale=2, sigma=None, order=1, upscale : float, optional Upscale factor. sigma : float, optional - Sigma for gaussian filter. Default is `2 * upscale / 6.0` which + Sigma for Gaussian filter. Default is `2 * upscale / 6.0` which corresponds to a filter mask twice the size of the scale factor that - covers more than 99% of the gaussian distribution. + covers more than 99% of the Gaussian distribution. order : int, optional Order of splines used in interpolation of upsampling. See - `scipy.ndimage.map_coordinates` for detail. - mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional + `skimage.transform.warp` for detail. + mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. cval : float, optional @@ -137,7 +137,7 @@ def pyramid_expand(image, upscale=2, sigma=None, order=1, def pyramid_gaussian(image, max_layer=-1, downscale=2, sigma=None, order=1, mode='reflect', cval=0): - """Yield images of the gaussian pyramid formed by the input image. + """Yield images of the Gaussian pyramid formed by the input image. Recursively applies the `pyramid_reduce` function to the image, and yields the downscaled images. @@ -157,13 +157,13 @@ def pyramid_gaussian(image, max_layer=-1, downscale=2, sigma=None, order=1, downscale : float, optional Downscale factor. sigma : float, optional - Sigma for gaussian filter. Default is `2 * downscale / 6.0` which + Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which corresponds to a filter mask twice the size of the scale factor that - covers more than 99% of the gaussian distribution. + covers more than 99% of the Gaussian distribution. order : int, optional Order of splines used in interpolation of downsampling. See - `scipy.ndimage.map_coordinates` for detail. - mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional + `skimage.transform.warp` for detail. + mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. cval : float, optional @@ -238,13 +238,13 @@ def pyramid_laplacian(image, max_layer=-1, downscale=2, sigma=None, order=1, downscale : float, optional Downscale factor. sigma : float, optional - Sigma for gaussian filter. Default is `2 * downscale / 6.0` which + Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which corresponds to a filter mask twice the size of the scale factor that - covers more than 99% of the gaussian distribution. + covers more than 99% of the Gaussian distribution. order : int, optional Order of splines used in interpolation of downsampling. See - `scipy.ndimage.map_coordinates` for detail. - mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional + `skimage.transform.warp` for detail. + mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. cval : float, optional