ó
 ‰\c           @   sƒ  d  d l  Z  d  d l Z d  d l m Z d d l m Z m Z m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z m Z m Z m Z e e e	 f Z d	 „  Z d d d
 e e d d d „ Z d d d
 e e d d d d „ Z e d d d d
 e e d „ Z d
 e d „ Z d „  Z d d d d
 d d d d
 e e d „
 Z d „  Z e j  d „ Z! d „  Z" i  d d d d e e d „ Z# d S(   iÿÿÿÿN(   t   ndimagei   (   t   SimilarityTransformt   AffineTransformt   ProjectiveTransformt   _to_ndimage_mode(   t
   _warp_fasti   (   t   block_reduce(   t   get_bound_method_classt   safe_as_intt   warnt   convert_to_floatc         C   s2   |  d  k	 r |  St d ƒ | d k r* t St Sd  S(   Ns¨   The default multichannel argument (None) is deprecated.  Please specify either True or False explicitly.  multichannel will default to False starting with release 0.16.i   (   t   NoneR	   t   Truet   False(   t   multichannelt   ndim(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   _multichannel_default   s    
i    c	         C   s*  | d k r d } t d ƒ n  | d k r> t } t d ƒ n  t | ƒ } t | ƒ }	 |  j }
 |	 |  j k r˜ |
 d |	 |  j }
 t j |  |
 ƒ }  nL |	 |  j d k rÂ | |  j d f } n" |	 |  j d k  rä t	 d ƒ ‚ n  t j
 |
 d t ƒt j
 | d t ƒ} | rÈ| d k r;t j d | d d	 ƒ } nl t j | ƒ t j | ƒ } t j | d k  ƒ r{t	 d
 ƒ ‚ n, t j | d k | d k @ƒ r§t d ƒ n  t j |  | d | d | ƒ}  n  t | ƒ d	 k s t | ƒ d k rl| d	 |
 d	 k rl| d } | d } |
 d } |
 d } | d k rh| d k rht d | d d | d d f ƒ } nÎ t j d d g d | g | | g g ƒ d } t j | j d t j ƒ} | d | d d … d f d d | d d … d f <| d | d d … d f d d | d d … d f <t ƒ  } | j | | ƒ t |  | d | d | d | d | d | d | ƒ} nº g  t | ƒ D]+ \ } } | | t j | ƒ d d ^ qy} t j t j d t d d | Œ ƒ } t |  | ƒ }  t | ƒ } t j |  | d | d | d | ƒ} t |  | | | | | ƒ | S(   s!  Resize image to match a certain size.

    Performs interpolation to up-size or down-size images. Note that anti-
    aliasing should be enabled when down-sizing images to avoid aliasing
    artifacts. For down-sampling N-dimensional images with an integer factor
    also see `skimage.transform.downscale_local_mean`.

    Parameters
    ----------
    image : ndarray
        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 is preserved. In case the
        number of input channels does not equal the number of output channels a
        n-dimensional interpolation is applied.

    Returns
    -------
    resized : ndarray
        Resized version of the input.

    Other parameters
    ----------------
    order : int, optional
        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 : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode.  Modes match the behaviour of `numpy.pad`.  The
        default mode is 'constant'.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
    anti_aliasing : bool, optional
        Whether to apply a Gaussian filter to smooth the image prior to
        down-scaling. It is crucial to filter when down-sampling the image to
        avoid aliasing artifacts.
    anti_aliasing_sigma : {float, tuple of floats}, optional
        Standard deviation for Gaussian filtering to avoid aliasing artifacts.
        By default, this value is chosen as (1 - s) / 2 where s is the
        down-scaling factor.

    Notes
    -----
    Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
    pixels are duplicated during the reflection.  As an example, if an array
    has values [0, 1, 2] and was padded to the right by four values using
    symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
    would be [0, 1, 2, 1, 0, 1, 2].

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.transform import resize
    >>> image = data.camera()
    >>> resize(image, (100, 100), mode='reflect').shape
    (100, 100)

    t   constantsK   The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.so   Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.i   iÿÿÿÿs=   len(output_shape) cannot be smaller than the image dimensionst   dtypei    i   sF   Anti-aliasing standard deviation must be greater than or equal to zerosW   Anti-aliasing standard deviation greater than zero but not down-sampling along all axest   cvalt   modei   t   translationg       @g      à?Nt   output_shapet   ordert   clipt   preserve_ranget   sparset   indexingt   ij(   i   (   R   R	   R   t   tuplet   lent   shapeR   t   npt   reshapet
   ValueErrort   asarrayt   floatt   maximumt
   atleast_1dt	   ones_liket   anyt   ndit   gaussian_filterR   t   arrayt   zerost   doublet   estimatet   warpt	   enumeratet   aranget   meshgridR
   R   t   map_coordinatest   _clip_warp_output(   t   imageR   R   R   R   R   R   t   anti_aliasingt   anti_aliasing_sigmat   output_ndimt   input_shapet   factorst   rowst   colst
   input_rowst
   input_colst   tformt   src_cornerst   dst_cornerst   outt   it   dt   coord_arrayst	   coord_mapt   ndi_mode(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   resize"   sr    E	$



.66	;c
         C   s  t  | |  j ƒ } t j | ƒ } t | ƒ d k r¡ | rO t | ƒ |  j k sn | r} t | ƒ |  j d k r} t d ƒ ‚ n  | r¡ t j | d g f ƒ } q¡ n  t j |  j ƒ }
 t j	 | |
 ƒ } | rÝ |
 d | d <n  t
 |  | d | d | d | d | d | d	 | d
 |	 ƒS(   sÖ  Scale image by a certain factor.

    Performs interpolation to up-scale or down-scale images. Note that anti-
    aliasing should be enabled when down-sizing images to avoid aliasing
    artifacts. For down-sampling N-dimensional images with an integer factor
    also see `skimage.transform.downscale_local_mean`.

    Parameters
    ----------
    image : ndarray
        Input image.
    scale : {float, tuple of floats}
        Scale factors. Separate scale factors can be defined as
        `(rows, cols[, ...][, dim])`.

    Returns
    -------
    scaled : ndarray
        Scaled version of the input.

    Other parameters
    ----------------
    order : int, optional
        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 : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode.  Modes match the behaviour of `numpy.pad`.  The
        default mode is 'constant'.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
    multichannel : bool, optional
        Whether the last axis of the image is to be interpreted as multiple
        channels or another spatial dimension. By default, is set to True for
        3D (2D+color) inputs, and False for others. Starting in release 0.16,
        this will always default to False.
    anti_aliasing : bool, optional
        Whether to apply a Gaussian filter to smooth the image prior to
        down-scaling. It is crucial to filter when down-sampling the image to
        avoid aliasing artifacts.
    anti_aliasing_sigma : {float, tuple of floats}, optional
        Standard deviation for Gaussian filtering to avoid aliasing artifacts.
        By default, this value is chosen as (1 - s) / 2 where s is the
        down-scaling factor.

    Notes
    -----
    Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
    pixels are duplicated during the reflection.  As an example, if an array
    has values [0, 1, 2] and was padded to the right by four values using
    symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
    would be [0, 1, 2, 1, 0, 1, 2].

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.transform import rescale
    >>> image = data.camera()
    >>> rescale(image, 0.1, mode='reflect').shape
    (51, 51)
    >>> rescale(image, 0.5, mode='reflect').shape
    (256, 256)

    i   s4   Supply a single scale, or one value per spatial axisiÿÿÿÿR   R   R   R   R   R6   R7   (   R   R   R    R&   R   R"   t   concatenateR#   R   t   roundRH   (   R5   t   scaleR   R   R   R   R   R   R6   R7   t
   orig_shapeR   (    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   rescale¾   s     KR   c	         C   só  |  j  d |  j  d }	 }
 | d k rG t j |
 |	 f ƒ d d } n t j | ƒ } t d | ƒ } t d t j | ƒ ƒ } t d | ƒ } | | | } d } | rÂt j d d g d |	 d g |
 d |	 d g |
 d d g g ƒ } | j | ƒ } | d d … d f j ƒ  } | d d … d f j ƒ  } | d d … d f j	 ƒ  } | d d … d f j	 ƒ  } | | d } | | d } t j
 | | f ƒ } | | f } t d | ƒ } | | } n  t |  | d | d	 | d
 | d | d | d | ƒS(   ss	  Rotate image by a certain angle around its center.

    Parameters
    ----------
    image : ndarray
        Input image.
    angle : float
        Rotation angle in degrees in counter-clockwise direction.
    resize : bool, optional
        Determine whether the shape of the output image will be automatically
        calculated, so the complete rotated image exactly fits. Default is
        False.
    center : iterable of length 2
        The rotation center. If ``center=None``, the image is rotated around
        its center, i.e. ``center=(cols / 2 - 0.5, rows / 2 - 0.5)``.  Please
        note that this parameter is (cols, rows), contrary to normal skimage
        ordering.

    Returns
    -------
    rotated : ndarray
        Rotated version of the input.

    Other parameters
    ----------------
    order : int, optional
        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 : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode.  Modes match the behaviour of `numpy.pad`.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.

    Notes
    -----
    Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
    pixels are duplicated during the reflection.  As an example, if an array
    has values [0, 1, 2] and was padded to the right by four values using
    symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
    would be [0, 1, 2, 1, 0, 1, 2].

    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)

    i    i   g       @g      à?R   t   rotationNR   R   R   R   R   R   (   R   R   R    R+   R#   R   t   deg2radt   inverset   mint   maxt   ceilR/   (   R5   t   angleRH   t   centerR   R   R   R   R   R;   R<   t   tform1t   tform2t   tform3R?   R   t   cornerst   minct   minrt   maxct   maxrt   out_rowst   out_colsR   t   tform4(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   rotate  s8    B 	c         C   s   t  |  | t j | ƒ S(   sY  Down-sample N-dimensional image by local averaging.

    The image is padded with `cval` if it is not perfectly divisible by the
    integer factors.

    In contrast to the 2-D interpolation in `skimage.transform.resize` and
    `skimage.transform.rescale` this function may be applied to N-dimensional
    images and calculates the local mean of elements in each block of size
    `factors` in the input image.

    Parameters
    ----------
    image : ndarray
        N-dimensional input image.
    factors : array_like
        Array containing down-sampling integer factor along each axis.
    cval : float, optional
        Constant padding value if image is not perfectly divisible by the
        integer factors.

    Returns
    -------
    image : ndarray
        Down-sampled image with same number of dimensions as input image.

    Examples
    --------
    >>> a = np.arange(15).reshape(3, 5)
    >>> a
    array([[ 0,  1,  2,  3,  4],
           [ 5,  6,  7,  8,  9],
           [10, 11, 12, 13, 14]])
    >>> downscale_local_mean(a, (2, 3))
    array([[ 3.5,  4. ],
           [ 5.5,  4.5]])

    (   R   R    t   mean(   R5   R:   R   R   (    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   downscale_local_mean†  s    &c         C   sÃ   |  j  \ } } | \ } } t j | | d | | d ƒ }	 | d t j d ƒ } | | t j |	 | ƒ t j | | | | ƒ }
 | |	 t j |
 ƒ |  d <| |	 t j |
 ƒ |  d <|  S(   Ni   i   .i    i   (   .i    (   .i   (   t   TR    t   sqrtt   logt   expt   arctan2t   cost   sin(   t   xyRU   RN   t   strengtht   radiust   xt   yt   x0t   y0t   rhot   theta(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   _swirl_mapping¯  s    #id   c         C   s®   | d k r t d ƒ d } n  | d k rU t j |  j ƒ d  d d d … d } n  i | d 6| d 6| d 6| d	 6} t |  t d
 | d | d | d | d | d |	 d |
 ƒS(   sÖ  Perform a swirl transformation.

    Parameters
    ----------
    image : ndarray
        Input image.
    center : (column, row) tuple or (2,) ndarray, optional
        Center coordinate of transformation.
    strength : float, optional
        The amount of swirling applied.
    radius : float, optional
        The extent of the swirl in pixels.  The effect dies out
        rapidly beyond `radius`.
    rotation : float, optional
        Additional rotation applied to the image.

    Returns
    -------
    swirled : ndarray
        Swirled version of the input.

    Other parameters
    ----------------
    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 1. The order has to
        be in the range 0-5. See `skimage.transform.warp` for detail.
    mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode, with 'constant' used as the default. Modes match
        the behaviour of `numpy.pad`.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.

    s\   The default of `mode` in `skimage.transform.swirl` will change to `reflect` in version 0.15.R   i   NiÿÿÿÿRU   RN   Rl   Rm   t   map_argsR   R   R   R   R   R   (   R   R	   R    R+   R   R/   Rt   (   R5   RU   Rl   Rm   RN   R   R   R   R   R   R   t	   warp_args(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   swirlÂ  s    0
	*

c         C   s@   |  j  d k r5 | d d … d d … t j f |  (n | |  (d S(   s5  Copy b into each color layer of a, such that::

      a[:,:,0] = a[:,:,1] = ... = b

    Parameters
    ----------
    a : (M, N) or (M, N, P) ndarray
        Target array.
    b : (M, N)
        Source array.

    Notes
    -----
    Color images are stored as an ``(M, N, 3)`` or ``(M, N, 4)`` arrays.

    i   N(   R   R    t   newaxis(   t   at   b(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt
   _stackcopy  s    &c         C   s%  t  | ƒ } | d | d } } t | ƒ | | g } t | ƒ d k r\ | j | d ƒ n  t j | d | ƒ} t j | | f d | ƒj d d ƒ j } |  | ƒ } | j j d | | f ƒ j d d ƒ } t	 | d | d	 ƒ t	 | d
 | d ƒ t | ƒ d k r!t
 | d ƒ | d <n  | S(   sé  Build the source coordinates for the output of a 2-D image warp.

    Parameters
    ----------
    coord_map : callable like GeometricTransform.inverse
        Return input coordinates for given output coordinates.
        Coordinates are in the shape (P, 2), where P is the number
        of coordinates and each element is a ``(row, col)`` pair.
    shape : tuple
        Shape of output image ``(rows, cols[, bands])``.
    dtype : np.dtype or string
        dtype for return value (sane choices: float32 or float64).

    Returns
    -------
    coords : (ndim, rows, cols[, bands]) array of dtype `dtype`
            Coordinates for `scipy.ndimage.map_coordinates`, that will yield
            an image of shape (orows, ocols, bands) by drawing from source
            points according to the `coord_transform_fn`.

    Notes
    -----

    This is a lower-level routine that produces the source coordinates for 2-D
    images used by `warp()`.

    It is provided separately from `warp` to give additional flexibility to
    users who would like, for example, to re-use a particular coordinate
    mapping, to use specific dtypes at various points along the the
    image-warping process, or to implement different post-processing logic
    than `warp` performs after the call to `ndi.map_coordinates`.


    Examples
    --------
    Produce a coordinate map that shifts an image up and to the right:

    >>> from skimage import data
    >>> from scipy.ndimage import map_coordinates
    >>>
    >>> def shift_up10_left20(xy):
    ...     return xy - np.array([-20, 10])[None, :]
    >>>
    >>> image = data.astronaut().astype(np.float32)
    >>> coords = warp_coords(shift_up10_left20, image.shape)
    >>> warped_image = map_coordinates(image, coords)

    i    i   i   i   R   iÿÿÿÿ.(   i   .(   i    .(   i    .(   i   .(   i   .(   R   R   t   appendR    t   emptyt   indicesR!   Rd   t   swapaxesR{   t   range(   RF   R   R   R;   R<   t   coords_shapet   coordst	   tf_coords(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   warp_coords  s    1*'c   
      C   s›   | r— | d k r— |  j  ƒ  } |  j ƒ  } | d k oP | | k oM | k n } | rh | | k }	 n  t j | | | d | ƒ| r— | | |	 <q— n  d S(   sd  Clip output image to range of values of input image.

    Note that this function modifies the values of `output_image` in-place
    and it is only modified if ``clip=True``.

    Parameters
    ----------
    input_image : ndarray
        Input image.
    output_image : ndarray
        Output image, which is modified in-place.

    Other parameters
    ----------------
    order : int, optional
        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 : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode.  Modes match the behaviour of `numpy.pad`.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.

    i    R   RB   N(   RQ   RR   R    R   (
   t   input_imaget   output_imageR   R   R   R   t   min_valt   max_valt   preserve_cvalt	   cval_mask(    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyR4   i  s    g        c	            s6  t  |  | ƒ }  t j |  j ƒ }	 | d k r6 |	 } n t | ƒ } d }
 | d k ra t d ƒ n  | d k rêˆ rêd } t ˆ  t j ƒ r¤ ˆ  j d k r¤ ˆ  } nl t ˆ  t	 ƒ r¿ ˆ  j
 } nQ t ˆ  d ƒ rˆ  j d k rt ˆ  ƒ t	 k rt j j t j ˆ  ƒ j
 ƒ } n  | d k	 rê| j t j ƒ } |  j d k rgt |  | d | d	 | d
 | d | ƒ}
 qç|  j d k rçg  } xS t |  j d ƒ D]> } | j t |  d | f | d | d	 | d
 | d | ƒƒ qWt j | ƒ }
 qçqên  |
 d k rt ˆ  t j ƒ r)ˆ  j d k r)t d ˆ  ƒ ‰  n  t ˆ  t j ƒ rDˆ  } n |  j d k  sb|  j d k rqt d ƒ ‚ n  ‡  ‡ f d †  } t |	 ƒ d k rÅt | ƒ d k rÅ| d | d |	 d f } n  t | | ƒ } | d k } t | ƒ } t j |  | d | d
 | d	 | d | ƒ}
 n  t  |  |
 | | | | ƒ |
 S(   s=  Warp an image according to a given coordinate transformation.

    Parameters
    ----------
    image : ndarray
        Input image.
    inverse_map : transformation object, callable ``cr = f(cr, **kwargs)``, or ndarray
        Inverse coordinate map, which transforms coordinates in the output
        images into their corresponding coordinates in the input image.

        There are a number of different options to define this map, depending
        on the dimensionality of the input image. A 2-D image can have 2
        dimensions for gray-scale images, or 3 dimensions with color
        information.

         - For 2-D images, you can directly pass a transformation object,
           e.g. `skimage.transform.SimilarityTransform`, or its inverse.
         - For 2-D images, you can pass a ``(3, 3)`` homogeneous
           transformation matrix, e.g.
           `skimage.transform.SimilarityTransform.params`.
         - For 2-D images, a function that transforms a ``(M, 2)`` array of
           ``(col, row)`` coordinates in the output image to their
           corresponding coordinates in the input image. Extra parameters to
           the function can be specified through `map_args`.
         - For N-D images, you can directly pass an array of coordinates.
           The first dimension specifies the coordinates in the input image,
           while the subsequent dimensions determine the position in the
           output image. E.g. in case of 2-D images, you need to pass an array
           of shape ``(2, rows, cols)``, where `rows` and `cols` determine the
           shape of the output image, and the first dimension contains the
           ``(row, col)`` coordinate in the input image.
           See `scipy.ndimage.map_coordinates` for further documentation.

        Note, that a ``(3, 3)`` matrix is interpreted as a homogeneous
        transformation matrix, so you cannot interpolate values from a 3-D
        input, if the output is of shape ``(3,)``.

        See example section for usage.
    map_args : dict, optional
        Keyword arguments passed to `inverse_map`.
    output_shape : tuple (rows, cols), optional
        Shape of the output image generated. By default the shape of the input
        image is preserved.  Note that, even for multi-band images, only rows
        and columns need to be specified.
    order : int, optional
        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 : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
        Points outside the boundaries of the input are filled according
        to the given mode.  Modes match the behaviour of `numpy.pad`.
    cval : float, optional
        Used in conjunction with mode 'constant', the value outside
        the image boundaries.
    clip : bool, optional
        Whether to clip the output to the range of values of the input image.
        This is enabled by default, since higher order interpolation may
        produce values outside the given input range.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.

    Returns
    -------
    warped : double ndarray
        The warped input image.

    Notes
    -----
    - The input image is converted to a `double` image.
    - In case of a `SimilarityTransform`, `AffineTransform` and
      `ProjectiveTransform` and `order` in [0, 3] this function uses the
      underlying transformation matrix to warp the image with a much faster
      routine.

    Examples
    --------
    >>> from skimage.transform import warp
    >>> from skimage import data
    >>> image = data.camera()

    The following image warps are all equal but differ substantially in
    execution time. The image is shifted to the bottom.

    Use a geometric transform to warp an image (fast):

    >>> from skimage.transform import SimilarityTransform
    >>> tform = SimilarityTransform(translation=(0, -10))
    >>> warped = warp(image, tform)

    Use a callable (slow):

    >>> def shift_down(xy):
    ...     xy[:, 1] -= 10
    ...     return xy
    >>> warped = warp(image, shift_down)

    Use a transformation matrix to warp an image (fast):

    >>> matrix = np.array([[1, 0, 0], [0, 1, -10], [0, 0, 1]])
    >>> warped = warp(image, matrix)
    >>> from skimage.transform import ProjectiveTransform
    >>> warped = warp(image, ProjectiveTransform(matrix=matrix))

    You can also use the inverse of a geometric transformation (fast):

    >>> warped = warp(image, tform.inverse)

    For N-D images you can pass a coordinate array, that specifies the
    coordinates in the input image for every element in the output image. E.g.
    if you want to rescale a 3-D cube, you can do:

    >>> cube_shape = np.array([30, 30, 30])
    >>> cube = np.random.rand(*cube_shape)

    Setup the coordinate array, that defines the scaling:

    >>> scale = 0.1
    >>> output_shape = (scale * cube_shape).astype(int)
    >>> coords0, coords1, coords2 = np.mgrid[:output_shape[0],
    ...                    :output_shape[1], :output_shape[2]]
    >>> coords = np.array([coords0, coords1, coords2])

    Assume that the cube contains spatial data, where the first array element
    center is at coordinate (0.5, 0.5, 0.5) in real space, i.e. we have to
    account for this extra offset when scaling the image:

    >>> coords = (coords + 0.5) / scale - 0.5
    >>> warped = warp(cube, coords)

    i   sZ  Bi-quadratic interpolation behavior has changed due to a bug in the implementation of scikit-image. The new version now serves as a wrapper around SciPy's interpolation functions, which itself is not verified to be a correct implementation. Until skimage's implementation is fixed, we recommend to use bi-linear or bi-cubic interpolation instead.i    i   i   t   __name__RP   R   R   R   R   .t   matrixs\   Only 2-D images (grayscale or color) are supported, when providing a callable `inverse_map`.c             s   ˆ  |  ˆ Ž  S(   N(    (   t   args(   t   inverse_mapRu   (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyRF   m  s    t	   prefilterN(   i    i   i   (   i   i   (   i   i   (!   R
   R    R+   R   R   R   R	   t
   isinstancet   ndarrayt   HOMOGRAPHY_TRANSFORMSt   paramst   hasattrR‹   R   t   linalgt   invt   sixt   get_method_selft   astypeR-   R   R   R€   R|   t   dstackR   R"   R   R„   R   R)   R3   R4   (   R5   RŽ   Ru   R   R   R   R   R   R   R9   t   warpedRŒ   t   dimst   dimR‚   RF   R   RG   (    (   RŽ   Ru   s7   lib/python2.7/site-packages/skimage/transform/_warps.pyR/   —  sd    ‰	!	!	$($   R—   t   numpyR    t   scipyR    R)   t
   _geometricR   R   R   R   t	   _warps_cyR   t   measureR   t   _shared.utilsR   R   R	   R
   R’   R   R   R   R   RH   RM   Ra   Rc   Rt   Rw   R{   t   float64R„   R4   R/   (    (    (    s7   lib/python2.7/site-packages/skimage/transform/_warps.pyt   <module>   s6   ""		›]h)	@	N	.	