ó
 ‰\c           @   sÙ   d  d l  Z  d  d l Z d  d l m Z d d l m Z d „  Z d „  Z d „  Z	 d e
 f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d d e j d d d d „ Z d S(   iÿÿÿÿN(   t   optimizei   (   t   check_random_statec         C   s9   |  j  d k s" |  j d | k r5 t d | ƒ ‚ n  d  S(   Ni   i   s#   Input data must have shape (N, %d).(   t   ndimt   shapet
   ValueError(   t   datat   dim(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   _check_data_dim   s    "c         C   s5   |  j  d k  s" |  j d d k  r1 t d ƒ ‚ n  d  S(   Ni   i   s   Input data must be at least 2D.(   R   R   R   (   R   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   _check_data_atleast_2D   s    "c         C   s   t  j t  j d |  |  ƒ ƒ S(   sF   NumPy < 1.8 does not support the `axis` argument for `np.linalg.norm`.s   ij,ij->i(   t   npt   sqrtt   einsum(   t   xt   axis(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   _norm_along_axis   s    t	   BaseModelc           B   s   e  Z d  „  Z RS(   c         C   s   d  |  _ d  S(   N(   t   Nonet   params(   t   self(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   __init__   s    (   t   __name__t
   __module__R   (    (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR      s   t   LineModelNDc           B   sJ   e  Z d  Z d „  Z d d „ Z d d d „ Z d d „ Z d d „ Z RS(   sŽ  Total least squares estimator for N-dimensional lines.

    In contrast to ordinary least squares line estimation, this estimator
    minimizes the orthogonal distances of points to the estimated line.

    Lines are defined by a point (origin) and a unit vector (direction)
    according to the following vector equation::

        X = origin + lambda * direction

    Attributes
    ----------
    params : tuple
        Line model parameters in the following order `origin`, `direction`.

    Examples
    --------
    >>> x = np.linspace(1, 2, 25)
    >>> y = 1.5 * x + 3
    >>> lm = LineModelND()
    >>> lm.estimate(np.array([x, y]).T)
    True
    >>> tuple(np.round(lm.params, 5))
    (array([ 1.5 ,  5.25]), array([ 0.5547 ,  0.83205]))
    >>> res = lm.residuals(np.array([x, y]).T)
    >>> np.abs(np.round(res, 9))
    array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
            0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
    >>> np.round(lm.predict_y(x[:5]), 3)
    array([ 4.5  ,  4.562,  4.625,  4.688,  4.75 ])
    >>> np.round(lm.predict_x(y[:5]), 3)
    array([ 1.   ,  1.042,  1.083,  1.125,  1.167])

    c         C   sÙ   t  | ƒ | j d d ƒ } | | } | j d d k ry | d | d } t j j | ƒ } | d k rÆ | | :} qÆ nM | j d d k rº t j j | d t ƒ\ } } } | d } n t d ƒ ‚ | | f |  _	 t
 S(   s  Estimate line model from data.

        This minimizes the sum of shortest (orthogonal) distances
        from the given data points to the estimated line.

        Parameters
        ----------
        data : (N, dim) array
            N points in a space of dimensionality dim >= 2.

        Returns
        -------
        success : bool
            True, if model estimation succeeds.
        R   i    i   i   t   full_matricess   At least 2 input points needed.(   R   t   meanR   R	   t   linalgt   normt   svdt   FalseR   R   t   True(   R   R   t   origint	   directionR   t   _t   v(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   estimate@   s    

!c         C   s    t  | ƒ | d k r" |  j } n  | d k	 s4 t ‚ t | ƒ d k rU t d ƒ ‚ n  | \ } } | | t j | | | ƒ d t j f | } t	 | d d ƒS(   s  Determine residuals of data to model.

        For each point, the shortest (orthogonal) distance to the line is
        returned. It is obtained by projecting the data onto the line.

        Parameters
        ----------
        data : (N, dim) array
            N points in a space of dimension dim.
        params : (2, ) array, optional
            Optional custom parameter set in the form (`origin`, `direction`).

        Returns
        -------
        residuals : (N, ) array
            Residual for each data point.
        i   s!   Parameters are defined by 2 sets..R   i   N(
   R   R   R   t   AssertionErrort   lenR   R	   t   dott   newaxisR   (   R   R   R   R   R   t   res(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt	   residualse   s    
(i    c         C   s¯   | d k r |  j } n  | d k	 s* t ‚ t | ƒ d k rK t d ƒ ‚ n  | \ } } | | d k rz t d | ƒ ‚ n  | | | | | } | | d t j f | } | S(   sm  Predict intersection of the estimated line model with a hyperplane
        orthogonal to a given axis.

        Parameters
        ----------
        x : (n, 1) array
            Coordinates along an axis.
        axis : int
            Axis orthogonal to the hyperplane intersecting the line.
        params : (2, ) array, optional
            Optional custom parameter set in the form (`origin`, `direction`).

        Returns
        -------
        data : (n, m) array
            Predicted coordinates.

        Raises
        ------
        ValueError
            If the line is parallel to the given axis.
        i   s!   Parameters are defined by 2 sets.i    s   Line parallel to axis %s.N(   R   R   R#   R$   R   R	   R&   (   R   R   R   R   R   R   t   lR   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   predictƒ   s    c         C   s/   |  j  | d d d | ƒd d … d f } | S(   s¤  Predict x-coordinates for 2D lines using the estimated model.

        Alias for::

            predict(y, axis=1)[:, 0]

        Parameters
        ----------
        y : array
            y-coordinates.
        params : (2, ) array, optional
            Optional custom parameter set in the form (`origin`, `direction`).

        Returns
        -------
        x : array
            Predicted x-coordinates.

        R   i   R   Ni    (   R*   (   R   t   yR   R   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt	   predict_xª   s    +c         C   s/   |  j  | d d d | ƒd d … d f } | S(   s¤  Predict y-coordinates for 2D lines using the estimated model.

        Alias for::

            predict(x, axis=0)[:, 1]

        Parameters
        ----------
        x : array
            x-coordinates.
        params : (2, ) array, optional
            Optional custom parameter set in the form (`origin`, `direction`).

        Returns
        -------
        y : array
            Predicted y-coordinates.

        R   i    R   Ni   (   R*   (   R   R   R   R+   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt	   predict_yÁ   s    +N(	   R   R   t   __doc__R"   R   R(   R*   R,   R-   (    (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR      s   "	%'t   CircleModelc           B   s,   e  Z d  Z d „  Z d „  Z d d „ Z RS(   s¿  Total least squares estimator for 2D circles.

    The functional model of the circle is::

        r**2 = (x - xc)**2 + (y - yc)**2

    This estimator minimizes the squared distances from all points to the
    circle::

        min{ sum((r - sqrt((x_i - xc)**2 + (y_i - yc)**2))**2) }

    A minimum number of 3 points is required to solve for the parameters.

    Attributes
    ----------
    params : tuple
        Circle model parameters in the following order `xc`, `yc`, `r`.

    Examples
    --------
    >>> t = np.linspace(0, 2 * np.pi, 25)
    >>> xy = CircleModel().predict_xy(t, params=(2, 3, 4))
    >>> model = CircleModel()
    >>> model.estimate(xy)
    True
    >>> tuple(np.round(model.params, 5))
    (2.0, 3.0, 4.0)
    >>> res = model.residuals(xy)
    >>> np.abs(np.round(res, 9))
    array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
            0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

    c         C   s®  t  | d d ƒ| d d … d f } | d d … d f } | d | d } t j | ƒ } t j | ƒ } t j | | ƒ } t j t j | d ƒ | | g | t j | d ƒ | g | | t t | ƒ ƒ g g ƒ } t j t j | | ƒ t j | | ƒ t j | ƒ g g ƒ j }	 t j j | ƒ j	 |	 ƒ \ }
 } } |
 d | d | d }
 } } |
 d } | d } t j
 d | |
 d | d ƒ d } | | | f |  _ t S(   s/  Estimate circle model from data using total least squares.

        Parameters
        ----------
        data : (N, 2) array
            N points with ``(x, y)`` coordinates, respectively.

        Returns
        -------
        success : bool
            True, if model estimation succeeds.

        R   i   Ni    i   i   (   R   R	   t   sumt   arrayt   floatR$   t   TR   t   pinvR%   R
   R   R   (   R   R   R   R+   t   x2y2t   sum_xt   sum_yt   sum_xyt   m1t   m2t   at   bt   ct   xct   yct   r(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR"   ý   s(    !$ 

'c         C   ss   t  | d d ƒ|  j \ } } } | d d … d f } | d d … d f } | t j | | d | | d ƒ S(   sf  Determine residuals of data to model.

        For each point the shortest distance to the circle is returned.

        Parameters
        ----------
        data : (N, 2) array
            N points with ``(x, y)`` coordinates, respectively.

        Returns
        -------
        residuals : (N, ) array
            Residual for each data point.

        R   i   Ni    i   (   R   R   R	   R
   (   R   R   R>   R?   R@   R   R+   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR(   &  s
    c         C   sy   | d k r |  j } n  | \ } } } | | t j | ƒ } | | t j | ƒ } t j | d | d f d | j ƒS(   sÂ  Predict x- and y-coordinates using the estimated model.

        Parameters
        ----------
        t : array
            Angles in circle in radians. Angles start to count from positive
            x-axis to positive y-axis in a right-handed system.
        params : (3, ) array, optional
            Optional custom parameter set.

        Returns
        -------
        xy : (..., 2) array
            Predicted x- and y-coordinates.

        .R   N(   .N(   .N(   R   R   R	   t   cost   sint   concatenateR   (   R   t   tR   R>   R?   R@   R   R+   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt
   predict_xy@  s    N(   R   R   R.   R"   R(   R   RE   (    (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR/   Ù   s   "	)	t   EllipseModelc           B   s,   e  Z d  Z d „  Z d „  Z d d „ Z RS(   sj  Total least squares estimator for 2D ellipses.

    The functional model of the ellipse is::

        xt = xc + a*cos(theta)*cos(t) - b*sin(theta)*sin(t)
        yt = yc + a*sin(theta)*cos(t) + b*cos(theta)*sin(t)
        d = sqrt((x - xt)**2 + (y - yt)**2)

    where ``(xt, yt)`` is the closest point on the ellipse to ``(x, y)``. Thus
    d is the shortest distance from the point to the ellipse.

    The estimator is based on a least squares minimization. The optimal
    solution is computed directly, no iterations are required. This leads
    to a simple, stable and robust fitting method.

    The ``params`` attribute contains the parameters in the following order::

        xc, yc, a, b, theta

    Attributes
    ----------
    params : tuple
        Ellipse model parameters in the following order `xc`, `yc`, `a`, `b`,
        `theta`.

    Examples
    --------

    >>> xy = EllipseModel().predict_xy(np.linspace(0, 2 * np.pi, 25),
    ...                                params=(10, 15, 4, 8, np.deg2rad(30)))
    >>> ellipse = EllipseModel()
    >>> ellipse.estimate(xy)
    True
    >>> np.round(ellipse.params, 2)
    array([ 10.  ,  15.  ,   4.  ,   8.  ,   0.52])
    >>> np.round(abs(ellipse.residuals(xy)), 5)
    array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
            0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
    c         C   s5  t  | d d ƒ| d d … d f } | d d … d f } t j | d | | | d g ƒ j } t j | | t j t | ƒ ƒ g ƒ j } t j | j | ƒ } t j | j | ƒ } t j | j | ƒ } t j d d d g d d d g d d d g g ƒ }	 yG t j j	 |	 ƒ j | t j | t j j	 | ƒ ƒ j | j ƒ ƒ }
 Wn t j j
 k
 r`t SXt j j |
 ƒ \ } } d	 t j | d d d … f | d d d … f ƒ t j | d d d … f d ƒ } | d d … | d k f } d | j k st | j ƒ  ƒ d
 k rt S| j ƒ  \ } } } t j t j j	 | ƒ | j ƒ j | ƒ } | j ƒ  \ } } } | d :} | d :} | d :} | | | | | d | | } | | | | | d | | } | | d | | d | | d d | | | | | | } t j | | d d	 | d ƒ } | d | | | | | } | d | | | | | } t j d | | ƒ } t j d | | ƒ } d t j d | | | ƒ } | | k rÜ| d t j 7} n  t j | | | | | g ƒ j ƒ  |  _ g  |  j D] } t t j | ƒ ƒ ^ q|  _ t S(   sf  Estimate circle model from data using total least squares.

        Parameters
        ----------
        data : (N, 2) array
            N points with ``(x, y)`` coordinates, respectively.

        Returns
        -------
        success : bool
            True, if model estimation succeeds.


        References
        ----------
        .. [1] Halir, R.; Flusser, J. "Numerically stable direct least squares
               fitting of ellipses". In Proc. 6th International Conference in
               Central Europe on Computer Graphics and Visualization.
               WSCG (Vol. 98, pp. 125-132).

        R   i   Ni    i   g        g       @g      ð¿i   i   g      à?(   R   R	   t   vstackR3   t   onesR$   R%   R1   R   t   invt   LinAlgErrorR   t   eigt   multiplyt   powerR   t   ravelR
   t   arctant   pit
   nan_to_numt   tolistR   R2   t   realR   (   R   R   R   R+   t   D1t   D2t   S1t   S2t   S3t   C1t   Mt   eig_valst   eig_vecst   condt   a1R;   R<   R=   t   a2t   dt   ft   gt   x0t   y0t	   numeratort   termt   denominator1t   denominator2t   widtht   heightt   phi(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyR"   „  sP    '*353#'+


""B#'.c            sL  t  | d d ƒ|  j \ ‰ ‰ ‰  ‰ } t j | ƒ ‰ t j | ƒ ‰ | d d … d f } | d d … d f } | j d } ‡  ‡ ‡ ‡ ‡ ‡ f d †  } t j | f d t j ƒ} t j	 | ˆ | ˆ ƒ | } xo t
 | ƒ D]a }	 | |	 }
 | |	 } t j | | |	 d |
 | f ƒ\ } } t j | | |
 | ƒ ƒ | |	 <qã W| S(	   sg  Determine residuals of data to model.

        For each point the shortest distance to the ellipse is returned.

        Parameters
        ----------
        data : (N, 2) array
            N points with ``(x, y)`` coordinates, respectively.

        Returns
        -------
        residuals : (N, ) array
            Residual for each data point.

        R   i   Ni    i   c            sr   t  j |  ƒ } t  j |  ƒ } ˆ ˆ  ˆ | ˆ ˆ | } ˆ ˆ  ˆ | ˆ ˆ | } | | d | | d S(   Ni   (   t   mathRA   RB   (   RD   t   xit   yit   ctt   stt   xtt   yt(   R;   R<   t   cthetat   sthetaR>   R?   (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   fun   s
    t   dtypet   args(   R   R   Rl   RA   RB   R   R	   t   emptyt   doublet   arctan2t   rangeR    t   leastsqR
   (   R   R   t   thetaR   R+   t   NRu   R(   t   t0t   iRm   Rn   RD   R    (    (   R;   R<   Rs   Rt   R>   R?   s2   lib/python2.7/site-packages/skimage/measure/fit.pyR(   ã  s     

(#c         C   sÉ   | d k r |  j } n  | \ } } } } } t j | ƒ } t j | ƒ }	 t j | ƒ }
 t j | ƒ } | | |
 | | | |	 } | | | | | |
 |	 } t j | d | d f d | j ƒS(   sÂ  Predict x- and y-coordinates using the estimated model.

        Parameters
        ----------
        t : array
            Angles in circle in radians. Angles start to count from positive
            x-axis to positive y-axis in a right-handed system.
        params : (5, ) array, optional
            Optional custom parameter set.

        Returns
        -------
        xy : (..., 2) array
            Predicted x- and y-coordinates.

        .R   N(   .N(   .N(   R   R   R	   RA   RB   Rl   RC   R   (   R   RD   R   R>   R?   R;   R<   R}   Ro   Rp   Rs   Rt   R   R+   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyRE   !  s    N(   R   R   R.   R"   R(   R   RE   (    (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyRF   [  s   '	_	>c         C   s¶   |  d k r t  j Sd | } | d k r0 t  j S|  t | ƒ } d | | } | d k r^ d S| d k rq t  j St  j | ƒ } t  j | ƒ } | d k rŸ d St t  j | | ƒ ƒ S(   s  Determine number trials such that at least one outlier-free subset is
    sampled for the given inlier/outlier ratio.
    Parameters
    ----------
    n_inliers : int
        Number of inliers in the data.
    n_samples : int
        Total number of samples in the data.
    min_samples : int
        Minimum number of samples chosen randomly from original data.
    probability : float
        Probability (confidence) that one outlier-free sample is generated.
    Returns
    -------
    trials : int
        Number of trials.
    i    i   (   R	   t   infR2   t   logt   intt   ceil(   t	   n_inlierst	   n_samplest   min_samplest   probabilityt   nomt   inlier_ratiot   denom(    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   _dynamic_max_trialsC  s     
id   i    i   c         C   s¦  d } d } t j } d } t |
 ƒ }
 | d k  rB t d ƒ ‚ n  | d k  r] t d ƒ ‚ n  |	 d k  su |	 d k r„ t d ƒ ‚ n  t |  t ƒ r° t |  t ƒ r° |  g }  n  t |  ƒ }  |  d j d } xt	 | ƒ D]s} g  } |
 j
 d | | ƒ } x |  D] } | j | | ƒ qW| d k	 r<| | Œ  r<qÚ n  | ƒ  } | j | Œ  } | d k	 ro| soqÚ qon  | d k	 r‘| | | Œ r‘qÚ n  t j | j |  Œ  ƒ } | | k  } t j | d ƒ } t j | ƒ } | | k sû| | k rÚ | | k  rÚ | } | } | } | } | | k sF| | k sF| t | | | |	 ƒ k rMPqMqÚ qÚ W| d k	 rœx, t	 t |  ƒ ƒ D] } |  | | |  | <qpW| j |  Œ  n  | | f S(   sè  Fit a model to data with the RANSAC (random sample consensus) algorithm.

    RANSAC is an iterative algorithm for the robust estimation of parameters
    from a subset of inliers from the complete data set. Each iteration
    performs the following tasks:

    1. Select `min_samples` random samples from the original data and check
       whether the set of data is valid (see `is_data_valid`).
    2. Estimate a model to the random subset
       (`model_cls.estimate(*data[random_subset]`) and check whether the
       estimated model is valid (see `is_model_valid`).
    3. Classify all data as inliers or outliers by calculating the residuals
       to the estimated model (`model_cls.residuals(*data)`) - all data samples
       with residuals smaller than the `residual_threshold` are considered as
       inliers.
    4. Save estimated model as best model if number of inlier samples is
       maximal. In case the current estimated model has the same number of
       inliers, it is only considered as the best model if it has less sum of
       residuals.

    These steps are performed either a maximum number of times or until one of
    the special stop criteria are met. The final model is estimated using all
    inlier samples of the previously determined best model.

    Parameters
    ----------
    data : [list, tuple of] (N, D) array
        Data set to which the model is fitted, where N is the number of data
        points and D the dimensionality of the data.
        If the model class requires multiple input data arrays (e.g. source and
        destination coordinates of  ``skimage.transform.AffineTransform``),
        they can be optionally passed as tuple or list. Note, that in this case
        the functions ``estimate(*data)``, ``residuals(*data)``,
        ``is_model_valid(model, *random_data)`` and
        ``is_data_valid(*random_data)`` must all take each data array as
        separate arguments.
    model_class : object
        Object with the following object methods:

         * ``success = estimate(*data)``
         * ``residuals(*data)``

        where `success` indicates whether the model estimation succeeded
        (`True` or `None` for success, `False` for failure).
    min_samples : int
        The minimum number of data points to fit a model to.
    residual_threshold : float
        Maximum distance for a data point to be classified as an inlier.
    is_data_valid : function, optional
        This function is called with the randomly selected data before the
        model is fitted to it: `is_data_valid(*random_data)`.
    is_model_valid : function, optional
        This function is called with the estimated model and the randomly
        selected data: `is_model_valid(model, *random_data)`, .
    max_trials : int, optional
        Maximum number of iterations for random sample selection.
    stop_sample_num : int, optional
        Stop iteration if at least this number of inliers are found.
    stop_residuals_sum : float, optional
        Stop iteration if sum of residuals is less than or equal to this
        threshold.
    stop_probability : float in range [0, 1], optional
        RANSAC iteration stops if at least one outlier-free set of the
        training data is sampled with ``probability >= stop_probability``,
        depending on the current best model's inlier ratio and the number
        of trials. This requires to generate at least N samples (trials):

            N >= log(1 - probability) / log(1 - e**m)

        where the probability (confidence) is typically set to a high value
        such as 0.99, and e is the current fraction of inliers w.r.t. the
        total number of samples.
    random_state : int, RandomState instance or None, optional
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.


    Returns
    -------
    model : object
        Best model with largest consensus set.
    inliers : (N, ) array
        Boolean mask of inliers classified as ``True``.

    References
    ----------
    .. [1] "RANSAC", Wikipedia, http://en.wikipedia.org/wiki/RANSAC

    Examples
    --------

    Generate ellipse data without tilt and add noise:

    >>> t = np.linspace(0, 2 * np.pi, 50)
    >>> xc, yc = 20, 30
    >>> a, b = 5, 10
    >>> x = xc + a * np.cos(t)
    >>> y = yc + b * np.sin(t)
    >>> data = np.column_stack([x, y])
    >>> np.random.seed(seed=1234)
    >>> data += np.random.normal(size=data.shape)

    Add some faulty data:

    >>> data[0] = (100, 100)
    >>> data[1] = (110, 120)
    >>> data[2] = (120, 130)
    >>> data[3] = (140, 130)

    Estimate ellipse model using all available data:

    >>> model = EllipseModel()
    >>> model.estimate(data)
    True
    >>> np.round(model.params)  # doctest: +SKIP
    array([ 72.,  75.,  77.,  14.,   1.])

    Estimate ellipse model using RANSAC:

    >>> ransac_model, inliers = ransac(data, EllipseModel, 20, 3, max_trials=50)
    >>> abs(np.round(ransac_model.params))
    array([ 20.,  30.,   5.,  10.,   0.])
    >>> inliers # doctest: +SKIP
    array([False, False, False, False,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True], dtype=bool)
    >>> sum(inliers) > 40
    True

    Robustly estimate geometric transformation:

    >>> from skimage.transform import SimilarityTransform
    >>> np.random.seed(0)
    >>> src = 100 * np.random.rand(50, 2)
    >>> model0 = SimilarityTransform(scale=0.5, rotation=1,
    ...                              translation=(10, 20))
    >>> dst = model0(src)
    >>> dst[0] = (10000, 10000)
    >>> dst[1] = (-100, 100)
    >>> dst[2] = (50, 50)
    >>> model, inliers = ransac((src, dst), SimilarityTransform, 2, 10)
    >>> inliers
    array([False, False, False,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True,  True,  True,  True,  True,
            True,  True,  True,  True,  True], dtype=bool)

    i    s'   `min_samples` must be greater than zeros&   `max_trials` must be greater than zeroi   s*   `stop_probability` must be in range [0, 1]i   N(   R   R	   R   R   R   t
   isinstancet   listt   tupleR   R{   t   randintt   appendR"   t   absR(   R0   RŒ   R$   (   R   t   model_classR‡   t   residual_thresholdt   is_data_validt   is_model_validt
   max_trialst   stop_sample_numt   stop_residuals_sumt   stop_probabilityt   random_statet
   best_modelt   best_inlier_numt   best_inlier_residuals_sumt   best_inlierst   num_samplest
   num_trialst   samplest   random_idxsR`   t   sample_modelt   successt   sample_model_residualst   sample_model_inlierst   sample_model_residuals_sumt   sample_inlier_numR€   (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   ransack  sh     	 			(   Rl   t   numpyR	   t   scipyR    t   _shared.utilsR   R   R   R   t   objectR   R   R/   RF   RŒ   R   R   Rª   (    (    (    s2   lib/python2.7/site-packages/skimage/measure/fit.pyt   <module>   s   			½‚è	)