def maximum(input, labels=None, index=None):

return _select(input, labels, index, find_max=True)[<NUM_LIT:0>]<EOL>

Calculate the maximum of the values of an array over labeled regions.

Parameters
----------
input : array_like
    Array_like of values. For each region specified by `labels`, the
    maximal values of `input` over the region is computed.
labels : array_like, optional
    An array of integers marking different regions over which the
    maximum value of `input` is to be computed. `labels` must have the
    same shape as `input`. If `labels` is not specified, the maximum
    over the whole array is returned.
index : array_like, optional
    A list of region labels that are taken into account for computing the
    maxima. If index is None, the maximum over all elements where `labels`
    is non-zero is returned.

Returns
-------
output : float or list of floats
    List of maxima of `input` over the regions determined by `labels` and
    whose index is in `index`. If `index` or `labels` are not specified, a
    float is returned: the maximal value of `input` if `labels` is None,
    and the maximal value of elements where `labels` is greater than zero
    if `index` is None.

See also
--------
label, minimum, median, maximum_position, extrema, sum, mean, variance,
standard_deviation

Notes
-----
The function returns a Python list and not a Numpy array, use
`np.array` to convert the list to an array.

Examples
--------
>>> a = np.arange(16).reshape((4,4))
>>> a
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
>>> labels = np.zeros_like(a)
>>> labels[:2,:2] = 1
>>> labels[2:, 1:3] = 2
>>> labels
array([[1, 1, 0, 0],
       [1, 1, 0, 0],
       [0, 2, 2, 0],
       [0, 2, 2, 0]])
>>> from scipy import ndimage
>>> ndimage.maximum(a)
15.0
>>> ndimage.maximum(a, labels=labels, index=[1,2])
[5.0, 14.0]
>>> ndimage.maximum(a, labels=labels)
14.0

>>> b = np.array([[1, 2, 0, 0],
                  [5, 3, 0, 4],
                  [0, 0, 0, 7],
                  [9, 3, 0, 0]])
>>> labels, labels_nb = ndimage.label(b)
>>> labels
array([[1, 1, 0, 0],
       [1, 1, 0, 2],
       [0, 0, 0, 2],
       [3, 3, 0, 0]])
>>> ndimage.maximum(b, labels=labels, index=np.arange(1, labels_nb + 1))
[5.0, 7.0, 9.0]


def median(input, labels=None, index=None):

return _select(input, labels, index, find_median=True)[<NUM_LIT:0>]<EOL>

Calculate the median of the values of an array over labeled regions.

Parameters
----------
input : array_like
    Array_like of values. For each region specified by `labels`, the
    median value of `input` over the region is computed.
labels : array_like, optional
    An array_like of integers marking different regions over which the
    median value of `input` is to be computed. `labels` must have the
    same shape as `input`. If `labels` is not specified, the median
    over the whole array is returned.
index : array_like, optional
    A list of region labels that are taken into account for computing the
    medians. If index is None, the median over all elements where `labels`
    is non-zero is returned.

Returns
-------
median : float or list of floats
    List of medians of `input` over the regions determined by `labels` and
    whose index is in `index`. If `index` or `labels` are not specified, a
    float is returned: the median value of `input` if `labels` is None,
    and the median value of elements where `labels` is greater than zero
    if `index` is None.

See also
--------
label, minimum, maximum, extrema, sum, mean, variance, standard_deviation

Notes
-----
The function returns a Python list and not a Numpy array, use
`np.array` to convert the list to an array.

Examples
--------
>>> a = np.array([[1, 2, 0, 1],
...               [5, 3, 0, 4],
...               [0, 0, 0, 7],
...               [9, 3, 0, 0]])
>>> labels, labels_nb = ndimage.label(a)
>>> labels
array([[1, 1, 0, 2],
       [1, 1, 0, 2],
       [0, 0, 0, 2],
       [3, 3, 0, 0]])
>>> ndimage.median(a, labels=labels, index=np.arange(1, labels_nb + 1))
[2.5, 4.0, 6.0]
>>> ndimage.median(a)
1.0
>>> ndimage.median(a, labels=labels)
3.0


def minimum_position(input, labels=None, index=None):

dims = numpy.array(numpy.asarray(input).shape)<EOL>dim_prod = numpy.cumprod([<NUM_LIT:1>] + list(dims[:<NUM_LIT:0>:-<NUM_LIT:1>]))[::-<NUM_LIT:1>]<EOL>result = _select(input, labels, index, find_min_positions=True)[<NUM_LIT:0>]<EOL>if numpy.isscalar(result):<EOL><INDENT>return tuple((result // dim_prod) % dims)<EOL><DEDENT>return [tuple(v) for v in (result.reshape(-<NUM_LIT:1>, <NUM_LIT:1>) // dim_prod) % dims]<EOL>

Find the positions of the minimums of the values of an array at labels.

Parameters
----------
input : array_like
    Array_like of values.
labels : array_like, optional
    An array of integers marking different regions over which the
    position of the minimum value of `input` is to be computed.
    `labels` must have the same shape as `input`. If `labels` is not
    specified, the location of the first minimum over the whole
    array is returned.

    The `labels` argument only works when `index` is specified.
index : array_like, optional
    A list of region labels that are taken into account for finding the
    location of the minima. If `index` is None, the ``first`` minimum
    over all elements where `labels` is non-zero is returned.

    The `index` argument only works when `labels` is specified.

Returns
-------
output : list of tuples of ints
    Tuple of ints or list of tuples of ints that specify the location
    of minima of `input` over the regions determined by `labels` and
    whose index is in `index`.

    If `index` or `labels` are not specified, a tuple of ints is
    returned specifying the location of the first minimal value of `input`.

See also
--------
label, minimum, median, maximum_position, extrema, sum, mean, variance,
standard_deviation


def maximum_position(input, labels=None, index=None):

dims = numpy.array(numpy.asarray(input).shape)<EOL>dim_prod = numpy.cumprod([<NUM_LIT:1>] + list(dims[:<NUM_LIT:0>:-<NUM_LIT:1>]))[::-<NUM_LIT:1>]<EOL>result = _select(input, labels, index, find_max_positions=True)[<NUM_LIT:0>]<EOL>if numpy.isscalar(result):<EOL><INDENT>return tuple((result // dim_prod) % dims)<EOL><DEDENT>return [tuple(v) for v in (result.reshape(-<NUM_LIT:1>, <NUM_LIT:1>) // dim_prod) % dims]<EOL>

Find the positions of the maximums of the values of an array at labels.

For each region specified by `labels`, the position of the maximum
value of `input` within the region is returned.

Parameters
----------
input : array_like
    Array_like of values.
labels : array_like, optional
    An array of integers marking different regions over which the
    position of the maximum value of `input` is to be computed.
    `labels` must have the same shape as `input`. If `labels` is not
    specified, the location of the first maximum over the whole
    array is returned.

    The `labels` argument only works when `index` is specified.
index : array_like, optional
    A list of region labels that are taken into account for finding the
    location of the maxima.  If `index` is None, the first maximum
    over all elements where `labels` is non-zero is returned.

    The `index` argument only works when `labels` is specified.

Returns
-------
output : list of tuples of ints
    List of tuples of ints that specify the location of maxima of
    `input` over the regions determined by `labels` and whose index
    is in `index`.

    If `index` or `labels` are not specified, a tuple of ints is
    returned specifying the location of the ``first`` maximal value
    of `input`.

See also
--------
label, minimum, median, maximum_position, extrema, sum, mean, variance,
standard_deviation


def extrema(input, labels=None, index=None):

dims = numpy.array(numpy.asarray(input).shape)<EOL>dim_prod = numpy.cumprod([<NUM_LIT:1>] + list(dims[:<NUM_LIT:0>:-<NUM_LIT:1>]))[::-<NUM_LIT:1>]<EOL>minimums, min_positions, maximums, max_positions = _select(input, labels,<EOL>index,<EOL>find_min=True,<EOL>find_max=True,<EOL>find_min_positions=True,<EOL>find_max_positions=True)<EOL>if numpy.isscalar(minimums):<EOL><INDENT>return (minimums, maximums, tuple((min_positions // dim_prod) % dims),<EOL>tuple((max_positions // dim_prod) % dims))<EOL><DEDENT>min_positions = [tuple(v) for v in (min_positions.reshape(-<NUM_LIT:1>, <NUM_LIT:1>) // dim_prod) % dims]<EOL>max_positions = [tuple(v) for v in (max_positions.reshape(-<NUM_LIT:1>, <NUM_LIT:1>) // dim_prod) % dims]<EOL>return minimums, maximums, min_positions, max_positions<EOL>

Calculate the minimums and maximums of the values of an array
at labels, along with their positions.

Parameters
----------
input : ndarray
    Nd-image data to process.
labels : ndarray, optional
    Labels of features in input.
    If not None, must be same shape as `input`.
index : int or sequence of ints, optional
    Labels to include in output.  If None (default), all values where
    non-zero `labels` are used.

Returns
-------
minimums, maximums : int or ndarray
    Values of minimums and maximums in each feature.
min_positions, max_positions : tuple or list of tuples
    Each tuple gives the n-D coordinates of the corresponding minimum
    or maximum.

See Also
--------
maximum, minimum, maximum_position, minimum_position, center_of_mass

Examples
--------
>>> a = np.array([[1, 2, 0, 0],
                  [5, 3, 0, 4],
                  [0, 0, 0, 7],
                  [9, 3, 0, 0]])
>>> from scipy import ndimage
>>> ndimage.extrema(a)
(0, 9, (0, 2), (3, 0))

Features to process can be specified using `labels` and `index`:

>>> lbl, nlbl = ndimage.label(a)
>>> ndimage.extrema(a, lbl, index=np.arange(1, nlbl+1))
(array([1, 4, 3]),
 array([5, 7, 9]),
 [(0, 0), (1, 3), (3, 1)],
 [(1, 0), (2, 3), (3, 0)])

If no index is given, non-zero `labels` are processed:

>>> ndimage.extrema(a, lbl)
(1, 9, (0, 0), (3, 0))


def center_of_mass(input, labels=None, index=None):

normalizer = sum(input, labels, index)<EOL>grids = numpy.ogrid[[slice(<NUM_LIT:0>, i) for i in input.shape]]<EOL>results = [sum(input * grids[dir].astype(float), labels, index) / normalizer<EOL>for dir in range(input.ndim)]<EOL>if numpy.isscalar(results[<NUM_LIT:0>]):<EOL><INDENT>return tuple(results)<EOL><DEDENT>return [tuple(v) for v in numpy.array(results).T]<EOL>

Calculate the center of mass of the values of an array at labels.

Parameters
----------
input : ndarray
    Data from which to calculate center-of-mass.
labels : ndarray, optional
    Labels for objects in `input`, as generated by `ndimage.label`.
    Only used with `index`.  Dimensions must be the same as `input`.
index : int or sequence of ints, optional
    Labels for which to calculate centers-of-mass. If not specified,
    all labels greater than zero are used.  Only used with `labels`.

Returns
-------
center_of_mass : tuple, or list of tuples
    Coordinates of centers-of-mass.

Examples
--------
>>> a = np.array(([0,0,0,0],
                  [0,1,1,0],
                  [0,1,1,0],
                  [0,1,1,0]))
>>> from scipy import ndimage
>>> ndimage.measurements.center_of_mass(a)
(2.0, 1.5)

Calculation of multiple objects in an image

>>> b = np.array(([0,1,1,0],
                  [0,1,0,0],
                  [0,0,0,0],
                  [0,0,1,1],
                  [0,0,1,1]))
>>> lbl = ndimage.label(b)[0]
>>> ndimage.measurements.center_of_mass(b, lbl, [1,2])
[(0.33333333333333331, 1.3333333333333333), (3.5, 2.5)]


def histogram(input, min, max, bins, labels=None, index=None):

_bins = numpy.linspace(min, max, bins + <NUM_LIT:1>)<EOL>def _hist(vals):<EOL><INDENT>return numpy.histogram(vals, _bins)[<NUM_LIT:0>]<EOL><DEDENT>return labeled_comprehension(input, labels, index, _hist, object, None,<EOL>pass_positions=False)<EOL>

Calculate the histogram of the values of an array, optionally at labels.

Histogram calculates the frequency of values in an array within bins
determined by `min`, `max`, and `bins`. The `labels` and `index`
keywords can limit the scope of the histogram to specified sub-regions
within the array.

Parameters
----------
input : array_like
    Data for which to calculate histogram.
min, max : int
    Minimum and maximum values of range of histogram bins.
bins : int
    Number of bins.
labels : array_like, optional
    Labels for objects in `input`.
    If not None, must be same shape as `input`.
index : int or sequence of ints, optional
    Label or labels for which to calculate histogram. If None, all values
    where label is greater than zero are used

Returns
-------
hist : ndarray
    Histogram counts.

Examples
--------
>>> a = np.array([[ 0.    ,  0.2146,  0.5962,  0.    ],
                  [ 0.    ,  0.7778,  0.    ,  0.    ],
                  [ 0.    ,  0.    ,  0.    ,  0.    ],
                  [ 0.    ,  0.    ,  0.7181,  0.2787],
                  [ 0.    ,  0.    ,  0.6573,  0.3094]])
>>> from scipy import ndimage
>>> ndimage.measurements.histogram(a, 0, 1, 10)
array([13,  0,  2,  1,  0,  1,  1,  2,  0,  0])

With labels and no indices, non-zero elements are counted:

>>> lbl, nlbl = ndimage.label(a)
>>> ndimage.measurements.histogram(a, 0, 1, 10, lbl)
array([0, 0, 2, 1, 0, 1, 1, 2, 0, 0])

Indices can be used to count only certain objects:

>>> ndimage.measurements.histogram(a, 0, 1, 10, lbl, 2)
array([0, 0, 1, 1, 0, 0, 1, 1, 0, 0])


def watershed_ift(input, markers, structure=None, output=None):

input = numpy.asarray(input)<EOL>if input.dtype.type not in [numpy.uint8, numpy.uint16]:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if structure is None:<EOL><INDENT>structure = morphology.generate_binary_structure(input.ndim, <NUM_LIT:1>)<EOL><DEDENT>structure = numpy.asarray(structure, dtype=bool)<EOL>if structure.ndim != input.ndim:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>for ii in structure.shape:<EOL><INDENT>if ii != <NUM_LIT:3>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>if not structure.flags.contiguous:<EOL><INDENT>structure = structure.copy()<EOL><DEDENT>markers = numpy.asarray(markers)<EOL>if input.shape != markers.shape:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>integral_types = [numpy.int0,<EOL>numpy.int8,<EOL>numpy.int16,<EOL>numpy.int32,<EOL>numpy.int_,<EOL>numpy.int64,<EOL>numpy.intc,<EOL>numpy.intp]<EOL>if markers.dtype.type not in integral_types:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if isinstance(output, numpy.ndarray):<EOL><INDENT>if output.dtype.type not in integral_types:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output = markers.dtype<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>_nd_image.watershed_ift(input, markers, structure, output)<EOL>return return_value<EOL>

Apply watershed from markers using an iterative forest transform algorithm.

Parameters
----------
input : array_like
    Input.
markers : array_like
    Markers are points within each watershed that form the beginning
    of the process.  Negative markers are considered background markers
    which are processed after the other markers.
structure : structure element, optional
    A structuring element defining the connectivity of the object can be
    provided. If None, an element is generated with a squared
    connectivity equal to one.
out : ndarray
    An output array can optionally be provided.  The same shape as input.

Returns
-------
watershed_ift : ndarray
    Output.  Same shape as `input`.


@docfiller<EOL>def correlate1d(input, weights, axis=-<NUM_LIT:1>, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>weights = numpy.asarray(weights, dtype=numpy.float64)<EOL>if weights.ndim != <NUM_LIT:1> or weights.shape[<NUM_LIT:0>] < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if not weights.flags.contiguous:<EOL><INDENT>weights = weights.copy()<EOL><DEDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>if (len(weights) // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (len(weights) // <NUM_LIT:2> +<EOL>origin > len(weights)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.correlate1d(input, weights, axis, output, mode, cval,<EOL>origin)<EOL>return return_value<EOL>

Calculate a one-dimensional correlation along the given axis.

    The lines of the array along the given axis are correlated with the
    given weights.

    Parameters
    ----------
    %(input)s
    weights : array
        One-dimensional sequence of numbers.
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def convolve1d(input, weights, axis=-<NUM_LIT:1>, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

weights = weights[::-<NUM_LIT:1>]<EOL>origin = -origin<EOL>if not len(weights) & <NUM_LIT:1>:<EOL><INDENT>origin -= <NUM_LIT:1><EOL><DEDENT>return correlate1d(input, weights, axis, output, mode, cval, origin)<EOL>

Calculate a one-dimensional convolution along the given axis.

    The lines of the array along the given axis are convolved with the
    given weights.

    Parameters
    ----------
    %(input)s
    weights : ndarray
        One-dimensional sequence of numbers.
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s

    Returns
    -------
    convolve1d : ndarray
        Convolved array with same shape as input


@docfiller<EOL>def gaussian_filter1d(input, sigma, axis=-<NUM_LIT:1>, order=<NUM_LIT:0>, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, truncate=<NUM_LIT>):

if order not in range(<NUM_LIT:4>):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>sd = float(sigma)<EOL>lw = int(truncate * sd + <NUM_LIT:0.5>)<EOL>weights = [<NUM_LIT:0.0>] * (<NUM_LIT:2> * lw + <NUM_LIT:1>)<EOL>weights[lw] = <NUM_LIT:1.0><EOL>sum = <NUM_LIT:1.0><EOL>sd = sd * sd<EOL>for ii in range(<NUM_LIT:1>, lw + <NUM_LIT:1>):<EOL><INDENT>tmp = math.exp(-<NUM_LIT:0.5> * float(ii * ii) / sd)<EOL>weights[lw + ii] = tmp<EOL>weights[lw - ii] = tmp<EOL>sum += <NUM_LIT> * tmp<EOL><DEDENT>for ii in range(<NUM_LIT:2> * lw + <NUM_LIT:1>):<EOL><INDENT>weights[ii] /= sum<EOL><DEDENT>if order == <NUM_LIT:1>:  <EOL><INDENT>weights[lw] = <NUM_LIT:0.0><EOL>for ii in range(<NUM_LIT:1>, lw + <NUM_LIT:1>):<EOL><INDENT>x = float(ii)<EOL>tmp = -x / sd * weights[lw + ii]<EOL>weights[lw + ii] = -tmp<EOL>weights[lw - ii] = tmp<EOL><DEDENT><DEDENT>elif order == <NUM_LIT:2>:  <EOL><INDENT>weights[lw] *= -<NUM_LIT:1.0> / sd<EOL>for ii in range(<NUM_LIT:1>, lw + <NUM_LIT:1>):<EOL><INDENT>x = float(ii)<EOL>tmp = (x * x / sd - <NUM_LIT:1.0>) * weights[lw + ii] / sd<EOL>weights[lw + ii] = tmp<EOL>weights[lw - ii] = tmp<EOL><DEDENT><DEDENT>elif order == <NUM_LIT:3>:  <EOL><INDENT>weights[lw] = <NUM_LIT:0.0><EOL>sd2 = sd * sd<EOL>for ii in range(<NUM_LIT:1>, lw + <NUM_LIT:1>):<EOL><INDENT>x = float(ii)<EOL>tmp = (<NUM_LIT> - x * x / sd) * x * weights[lw + ii] / sd2<EOL>weights[lw + ii] = -tmp<EOL>weights[lw - ii] = tmp<EOL><DEDENT><DEDENT>return correlate1d(input, weights, axis, output, mode, cval, <NUM_LIT:0>)<EOL>

One-dimensional Gaussian filter.

    Parameters
    ----------
    %(input)s
    sigma : scalar
        standard deviation for Gaussian kernel
    %(axis)s
    order : {0, 1, 2, 3}, optional
        An order of 0 corresponds to convolution with a Gaussian
        kernel. An order of 1, 2, or 3 corresponds to convolution with
        the first, second or third derivatives of a Gaussian. Higher
        order derivatives are not implemented
    %(output)s
    %(mode)s
    %(cval)s
    truncate : float
        Truncate the filter at this many standard deviations.
        Default is 4.0.

    Returns
    -------
    gaussian_filter1d : ndarray


@docfiller<EOL>def gaussian_filter(input, sigma, order=<NUM_LIT:0>, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, truncate=<NUM_LIT>):

input = numpy.asarray(input)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>orders = _ni_support._normalize_sequence(order, input.ndim)<EOL>if not set(orders).issubset(set(range(<NUM_LIT:4>))):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>sigmas = _ni_support._normalize_sequence(sigma, input.ndim)<EOL>axes = list(range(input.ndim))<EOL>axes = [(axes[ii], sigmas[ii], orders[ii])<EOL>for ii in range(len(axes)) if sigmas[ii] > <NUM_LIT>]<EOL>if len(axes) > <NUM_LIT:0>:<EOL><INDENT>for axis, sigma, order in axes:<EOL><INDENT>gaussian_filter1d(input, sigma, axis, order, output,<EOL>mode, cval, truncate)<EOL>input = output<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[...] = input[...]<EOL><DEDENT>return return_value<EOL>

Multidimensional Gaussian filter.

    Parameters
    ----------
    %(input)s
    sigma : scalar or sequence of scalars
        Standard deviation for Gaussian kernel. The standard
        deviations of the Gaussian filter are given for each axis as a
        sequence, or as a single number, in which case it is equal for
        all axes.
    order : {0, 1, 2, 3} or sequence from same set, optional
        The order of the filter along each axis is given as a sequence
        of integers, or as a single number.  An order of 0 corresponds
        to convolution with a Gaussian kernel. An order of 1, 2, or 3
        corresponds to convolution with the first, second or third
        derivatives of a Gaussian. Higher order derivatives are not
        implemented
    %(output)s
    %(mode)s
    %(cval)s
    truncate : float
        Truncate the filter at this many standard deviations.
        Default is 4.0.

    Returns
    -------
    gaussian_filter : ndarray
        Returned array of same shape as `input`.

    Notes
    -----
    The multidimensional filter is implemented as a sequence of
    one-dimensional convolution filters. The intermediate arrays are
    stored in the same data type as the output. Therefore, for output
    types with a limited precision, the results may be imprecise
    because intermediate results may be stored with insufficient
    precision.


@docfiller<EOL>def prewitt(input, axis=-<NUM_LIT:1>, output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>):

input = numpy.asarray(input)<EOL>axis = _ni_support._check_axis(axis, input.ndim)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>correlate1d(input, [-<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>], axis, output, mode, cval, <NUM_LIT:0>)<EOL>axes = [ii for ii in range(input.ndim) if ii != axis]<EOL>for ii in axes:<EOL><INDENT>correlate1d(output, [<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>], ii, output, mode, cval, <NUM_LIT:0>,)<EOL><DEDENT>return return_value<EOL>

Calculate a Prewitt filter.

    Parameters
    ----------
    %(input)s
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s


@docfiller<EOL>def sobel(input, axis=-<NUM_LIT:1>, output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>):

input = numpy.asarray(input)<EOL>axis = _ni_support._check_axis(axis, input.ndim)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>correlate1d(input, [-<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>], axis, output, mode, cval, <NUM_LIT:0>)<EOL>axes = [ii for ii in range(input.ndim) if ii != axis]<EOL>for ii in axes:<EOL><INDENT>correlate1d(output, [<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:1>], ii, output, mode, cval, <NUM_LIT:0>)<EOL><DEDENT>return return_value<EOL>

Calculate a Sobel filter.

    Parameters
    ----------
    %(input)s
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s


@docfiller<EOL>def generic_laplace(input, derivative2, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>,<EOL>extra_arguments=(),<EOL>extra_keywords = None):

if extra_keywords is None:<EOL><INDENT>extra_keywords = {}<EOL><DEDENT>input = numpy.asarray(input)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>axes = list(range(input.ndim))<EOL>if len(axes) > <NUM_LIT:0>:<EOL><INDENT>derivative2(input, axes[<NUM_LIT:0>], output, mode, cval,<EOL>*extra_arguments, **extra_keywords)<EOL>for ii in range(<NUM_LIT:1>, len(axes)):<EOL><INDENT>tmp = derivative2(input, axes[ii], output.dtype, mode, cval,<EOL>*extra_arguments, **extra_keywords)<EOL>output += tmp<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[...] = input[...]<EOL><DEDENT>return return_value<EOL>

N-dimensional Laplace filter using a provided second derivative function

    Parameters
    ----------
    %(input)s
    derivative2 : callable
        Callable with the following signature::

            derivative2(input, axis, output, mode, cval,
                        *extra_arguments, **extra_keywords)

        See `extra_arguments`, `extra_keywords` below.
    %(output)s
    %(mode)s
    %(cval)s
    %(extra_keywords)s
    %(extra_arguments)s


@docfiller<EOL>def laplace(input, output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>):

def derivative2(input, axis, output, mode, cval):<EOL><INDENT>return correlate1d(input, [<NUM_LIT:1>, -<NUM_LIT:2>, <NUM_LIT:1>], axis, output, mode, cval, <NUM_LIT:0>)<EOL><DEDENT>return generic_laplace(input, derivative2, output, mode, cval)<EOL>

N-dimensional Laplace filter based on approximate second derivatives.

    Parameters
    ----------
    %(input)s
    %(output)s
    %(mode)s
    %(cval)s


@docfiller<EOL>def gaussian_laplace(input, sigma, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, **kwargs):

input = numpy.asarray(input)<EOL>def derivative2(input, axis, output, mode, cval, sigma, **kwargs):<EOL><INDENT>order = [<NUM_LIT:0>] * input.ndim<EOL>order[axis] = <NUM_LIT:2><EOL>return gaussian_filter(input, sigma, order, output, mode, cval,<EOL>**kwargs)<EOL><DEDENT>return generic_laplace(input, derivative2, output, mode, cval,<EOL>extra_arguments=(sigma,),<EOL>extra_keywords=kwargs)<EOL>

Multidimensional Laplace filter using gaussian second derivatives.

    Parameters
    ----------
    %(input)s
    sigma : scalar or sequence of scalars
        The standard deviations of the Gaussian filter are given for
        each axis as a sequence, or as a single number, in which case
        it is equal for all axes.
    %(output)s
    %(mode)s
    %(cval)s
    Extra keyword arguments will be passed to gaussian_filter().


@docfiller<EOL>def generic_gradient_magnitude(input, derivative, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>,<EOL>extra_arguments=(), extra_keywords = None):

if extra_keywords is None:<EOL><INDENT>extra_keywords = {}<EOL><DEDENT>input = numpy.asarray(input)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>axes = list(range(input.ndim))<EOL>if len(axes) > <NUM_LIT:0>:<EOL><INDENT>derivative(input, axes[<NUM_LIT:0>], output, mode, cval,<EOL>*extra_arguments, **extra_keywords)<EOL>numpy.multiply(output, output, output)<EOL>for ii in range(<NUM_LIT:1>, len(axes)):<EOL><INDENT>tmp = derivative(input, axes[ii], output.dtype, mode, cval,<EOL>*extra_arguments, **extra_keywords)<EOL>numpy.multiply(tmp, tmp, tmp)<EOL>output += tmp<EOL><DEDENT>if NumpyVersion(numpy.__version__) > '<STR_LIT>':<EOL><INDENT>numpy.sqrt(output, output, casting='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>numpy.sqrt(output, output)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[...] = input[...]<EOL><DEDENT>return return_value<EOL>

Gradient magnitude using a provided gradient function.

    Parameters
    ----------
    %(input)s
    derivative : callable
        Callable with the following signature::

            derivative(input, axis, output, mode, cval,
                       *extra_arguments, **extra_keywords)

        See `extra_arguments`, `extra_keywords` below.
        `derivative` can assume that `input` and `output` are ndarrays.
        Note that the output from `derivative` is modified inplace;
        be careful to copy important inputs before returning them.
    %(output)s
    %(mode)s
    %(cval)s
    %(extra_keywords)s
    %(extra_arguments)s


@docfiller<EOL>def gaussian_gradient_magnitude(input, sigma, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, **kwargs):

input = numpy.asarray(input)<EOL>def derivative(input, axis, output, mode, cval, sigma, **kwargs):<EOL><INDENT>order = [<NUM_LIT:0>] * input.ndim<EOL>order[axis] = <NUM_LIT:1><EOL>return gaussian_filter(input, sigma, order, output, mode,<EOL>cval, **kwargs)<EOL><DEDENT>return generic_gradient_magnitude(input, derivative, output, mode,<EOL>cval, extra_arguments=(sigma,),<EOL>extra_keywords=kwargs)<EOL>

Multidimensional gradient magnitude using Gaussian derivatives.

    Parameters
    ----------
    %(input)s
    sigma : scalar or sequence of scalars
        The standard deviations of the Gaussian filter are given for
        each axis as a sequence, or as a single number, in which case
        it is equal for all axes..
    %(output)s
    %(mode)s
    %(cval)s
    Extra keyword arguments will be passed to gaussian_filter().


@docfiller<EOL>def correlate(input, weights, output=None, mode='<STR_LIT>', cval=<NUM_LIT:0.0>,<EOL>origin=<NUM_LIT:0>):

return _correlate_or_convolve(input, weights, output, mode, cval,<EOL>origin, False)<EOL>

Multi-dimensional correlation.

The array is correlated with the given kernel.

Parameters
----------
input : array-like
    input array to filter
weights : ndarray
    array of weights, same number of dimensions as input
output : array, optional
    The ``output`` parameter passes an array in which to store the
    filter output.
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'. Default is 'reflect'
cval : scalar, optional
    Value to fill past edges of input if ``mode`` is 'constant'. Default
    is 0.0
origin : scalar, optional
    The ``origin`` parameter controls the placement of the filter.
    Default 0

See Also
--------
convolve : Convolve an image with a kernel.


@docfiller<EOL>def convolve(input, weights, output=None, mode='<STR_LIT>', cval=<NUM_LIT:0.0>,<EOL>origin=<NUM_LIT:0>):

return _correlate_or_convolve(input, weights, output, mode, cval,<EOL>origin, True)<EOL>

Multidimensional convolution.

The array is convolved with the given kernel.

Parameters
----------
input : array_like
    Input array to filter.
weights : array_like
    Array of weights, same number of dimensions as input
output : ndarray, optional
    The `output` parameter passes an array in which to store the
    filter output.
mode : {'reflect','constant','nearest','mirror', 'wrap'}, optional
    the `mode` parameter determines how the array borders are
    handled. For 'constant' mode, values beyond borders are set to be
    `cval`. Default is 'reflect'.
cval : scalar, optional
    Value to fill past edges of input if `mode` is 'constant'. Default
    is 0.0
origin : array_like, optional
    The `origin` parameter controls the placement of the filter.
    Default is 0.

Returns
-------
result : ndarray
    The result of convolution of `input` with `weights`.

See Also
--------
correlate : Correlate an image with a kernel.

Notes
-----
Each value in result is :math:`C_i = \\sum_j{I_{i+j-k} W_j}`, where
W is the `weights` kernel,
j is the n-D spatial index over :math:`W`,
I is the `input` and k is the coordinate of the center of
W, specified by `origin` in the input parameters.

Examples
--------
Perhaps the simplest case to understand is ``mode='constant', cval=0.0``,
because in this case borders (i.e. where the `weights` kernel, centered
on any one value, extends beyond an edge of `input`.

>>> a = np.array([[1, 2, 0, 0],
....    [5, 3, 0, 4],
....    [0, 0, 0, 7],
....    [9, 3, 0, 0]])
>>> k = np.array([[1,1,1],[1,1,0],[1,0,0]])
>>> from scipy import ndimage
>>> ndimage.convolve(a, k, mode='constant', cval=0.0)
array([[11, 10,  7,  4],
       [10,  3, 11, 11],
       [15, 12, 14,  7],
       [12,  3,  7,  0]])

Setting ``cval=1.0`` is equivalent to padding the outer edge of `input`
with 1.0's (and then extracting only the original region of the result).

>>> ndimage.convolve(a, k, mode='constant', cval=1.0)
array([[13, 11,  8,  7],
       [11,  3, 11, 14],
       [16, 12, 14, 10],
       [15,  6, 10,  5]])

With ``mode='reflect'`` (the default), outer values are reflected at the
edge of `input` to fill in missing values.

>>> b = np.array([[2, 0, 0],
                  [1, 0, 0],
                  [0, 0, 0]])
>>> k = np.array([[0,1,0],[0,1,0],[0,1,0]])
>>> ndimage.convolve(b, k, mode='reflect')
array([[5, 0, 0],
       [3, 0, 0],
       [1, 0, 0]])

This includes diagonally at the corners.

>>> k = np.array([[1,0,0],[0,1,0],[0,0,1]])
>>> ndimage.convolve(b, k)
array([[4, 2, 0],
       [3, 2, 0],
       [1, 1, 0]])

With ``mode='nearest'``, the single nearest value in to an edge in
`input` is repeated as many times as needed to match the overlapping
`weights`.

>>> c = np.array([[2, 0, 1],
                  [1, 0, 0],
                  [0, 0, 0]])
>>> k = np.array([[0, 1, 0],
                  [0, 1, 0],
                  [0, 1, 0],
                  [0, 1, 0],
                  [0, 1, 0]])
>>> ndimage.convolve(c, k, mode='nearest')
array([[7, 0, 3],
       [5, 0, 2],
       [3, 0, 1]])


@docfiller<EOL>def uniform_filter1d(input, size, axis=-<NUM_LIT:1>, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>if size < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if (size // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (size // <NUM_LIT:2> + origin >= size):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.uniform_filter1d(input, size, axis, output, mode, cval,<EOL>origin)<EOL>return return_value<EOL>

Calculate a one-dimensional uniform filter along the given axis.

    The lines of the array along the given axis are filtered with a
    uniform filter of given size.

    Parameters
    ----------
    %(input)s
    size : integer
        length of uniform filter
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def uniform_filter(input, size=<NUM_LIT:3>, output=None, mode="<STR_LIT>",<EOL>cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>output, return_value = _ni_support._get_output(output, input)<EOL>sizes = _ni_support._normalize_sequence(size, input.ndim)<EOL>origins = _ni_support._normalize_sequence(origin, input.ndim)<EOL>axes = list(range(input.ndim))<EOL>axes = [(axes[ii], sizes[ii], origins[ii])<EOL>for ii in range(len(axes)) if sizes[ii] > <NUM_LIT:1>]<EOL>if len(axes) > <NUM_LIT:0>:<EOL><INDENT>for axis, size, origin in axes:<EOL><INDENT>uniform_filter1d(input, int(size), axis, output, mode,<EOL>cval, origin)<EOL>input = output<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[...] = input[...]<EOL><DEDENT>return return_value<EOL>

Multi-dimensional uniform filter.

    Parameters
    ----------
    %(input)s
    size : int or sequence of ints
        The sizes of the uniform filter are given for each axis as a
        sequence, or as a single number, in which case the size is
        equal for all axes.
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s

    Notes
    -----
    The multi-dimensional filter is implemented as a sequence of
    one-dimensional uniform filters. The intermediate arrays are stored
    in the same data type as the output. Therefore, for output types
    with a limited precision, the results may be imprecise because
    intermediate results may be stored with insufficient precision.


@docfiller<EOL>def minimum_filter1d(input, size, axis=-<NUM_LIT:1>, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>if size < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if (size // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (size // <NUM_LIT:2> + origin >= size):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.min_or_max_filter1d(input, size, axis, output, mode, cval,<EOL>origin, <NUM_LIT:1>)<EOL>return return_value<EOL>

Calculate a one-dimensional minimum filter along the given axis.

    The lines of the array along the given axis are filtered with a
    minimum filter of given size.

    Parameters
    ----------
    %(input)s
    size : int
        length along which to calculate 1D minimum
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s

    Notes
    -----
    This function implements the MINLIST algorithm [1]_, as described by
    Richard Harter [2]_, and has a guaranteed O(n) performance, `n` being
    the `input` length, regardless of filter size.

    References
    ----------
    .. [1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.2777
    .. [2] http://www.richardhartersworld.com/cri/2001/slidingmin.html


@docfiller<EOL>def maximum_filter1d(input, size, axis=-<NUM_LIT:1>, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>if size < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if (size // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (size // <NUM_LIT:2> + origin >= size):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.min_or_max_filter1d(input, size, axis, output, mode, cval,<EOL>origin, <NUM_LIT:0>)<EOL>return return_value<EOL>

Calculate a one-dimensional maximum filter along the given axis.

    The lines of the array along the given axis are filtered with a
    maximum filter of given size.

    Parameters
    ----------
    %(input)s
    size : int
        Length along which to calculate the 1-D maximum.
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s

    Returns
    -------
    maximum1d : ndarray, None
        Maximum-filtered array with same shape as input.
        None if `output` is not None

    Notes
    -----
    This function implements the MAXLIST algorithm [1]_, as described by
    Richard Harter [2]_, and has a guaranteed O(n) performance, `n` being
    the `input` length, regardless of filter size.

    References
    ----------
    .. [1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.2777
    .. [2] http://www.richardhartersworld.com/cri/2001/slidingmin.html


@docfiller<EOL>def minimum_filter(input, size=None, footprint=None, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

return _min_or_max_filter(input, size, footprint, None, output, mode,<EOL>cval, origin, <NUM_LIT:1>)<EOL>

Calculates a multi-dimensional minimum filter.

    Parameters
    ----------
    %(input)s
    %(size_foot)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def maximum_filter(input, size=None, footprint=None, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

return _min_or_max_filter(input, size, footprint, None, output, mode,<EOL>cval, origin, <NUM_LIT:0>)<EOL>

Calculates a multi-dimensional maximum filter.

    Parameters
    ----------
    %(input)s
    %(size_foot)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def rank_filter(input, rank, size=None, footprint=None, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

return _rank_filter(input, rank, size, footprint, output, mode, cval,<EOL>origin, '<STR_LIT>')<EOL>

Calculates a multi-dimensional rank filter.

    Parameters
    ----------
    %(input)s
    rank : integer
        The rank parameter may be less then zero, i.e., rank = -1
        indicates the largest element.
    %(size_foot)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def median_filter(input, size=None, footprint=None, output=None,<EOL>mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

return _rank_filter(input, <NUM_LIT:0>, size, footprint, output, mode, cval,<EOL>origin, '<STR_LIT>')<EOL>

Calculates a multidimensional median filter.

Parameters
----------
%(input)s
%(size_foot)s
%(output)s
%(mode)s
%(cval)s
%(origin)s

Returns
-------
median_filter : ndarray
    Return of same shape as `input`.


@docfiller<EOL>def percentile_filter(input, percentile, size=None, footprint=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>):

return _rank_filter(input, percentile, size, footprint, output, mode,<EOL>cval, origin, '<STR_LIT>')<EOL>

Calculates a multi-dimensional percentile filter.

    Parameters
    ----------
    %(input)s
    percentile : scalar
        The percentile parameter may be less then zero, i.e.,
        percentile = -20 equals percentile = 80
    %(size_foot)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s


@docfiller<EOL>def generic_filter1d(input, function, filter_size, axis=-<NUM_LIT:1>,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>,<EOL>extra_arguments=(), extra_keywords = None):

if extra_keywords is None:<EOL><INDENT>extra_keywords = {}<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if filter_size < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>if (filter_size // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (filter_size // <NUM_LIT:2> + origin >=<EOL>filter_size):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.generic_filter1d(input, function, filter_size, axis, output,<EOL>mode, cval, origin, extra_arguments, extra_keywords)<EOL>return return_value<EOL>

Calculate a one-dimensional filter along the given axis.

    `generic_filter1d` iterates over the lines of the array, calling the
    given function at each line. The arguments of the line are the
    input line, and the output line. The input and output lines are 1D
    double arrays.  The input line is extended appropriately according
    to the filter size and origin. The output line must be modified
    in-place with the result.

    Parameters
    ----------
    %(input)s
    function : callable
        Function to apply along given axis.
    filter_size : scalar
        Length of the filter.
    %(axis)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s
    %(extra_arguments)s
    %(extra_keywords)s


@docfiller<EOL>def generic_filter(input, function, size=None, footprint=None,<EOL>output=None, mode="<STR_LIT>", cval=<NUM_LIT:0.0>, origin=<NUM_LIT:0>,<EOL>extra_arguments=(), extra_keywords = None):

if extra_keywords is None:<EOL><INDENT>extra_keywords = {}<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>origins = _ni_support._normalize_sequence(origin, input.ndim)<EOL>if footprint is None:<EOL><INDENT>if size is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>sizes = _ni_support._normalize_sequence(size, input.ndim)<EOL>footprint = numpy.ones(sizes, dtype=bool)<EOL><DEDENT>else:<EOL><INDENT>footprint = numpy.asarray(footprint)<EOL>footprint = footprint.astype(bool)<EOL><DEDENT>fshape = [ii for ii in footprint.shape if ii > <NUM_LIT:0>]<EOL>if len(fshape) != input.ndim:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>for origin, lenf in zip(origins, fshape):<EOL><INDENT>if (lenf // <NUM_LIT:2> + origin < <NUM_LIT:0>) or (lenf // <NUM_LIT:2> + origin >= lenf):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>if not footprint.flags.contiguous:<EOL><INDENT>footprint = footprint.copy()<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>mode = _ni_support._extend_mode_to_code(mode)<EOL>_nd_image.generic_filter(input, function, footprint, output, mode,<EOL>cval, origins, extra_arguments, extra_keywords)<EOL>return return_value<EOL>

Calculates a multi-dimensional filter using the given function.

    At each element the provided function is called. The input values
    within the filter footprint at that element are passed to the function
    as a 1D array of double values.

    Parameters
    ----------
    %(input)s
    function : callable
        Function to apply at each element.
    %(size_foot)s
    %(output)s
    %(mode)s
    %(cval)s
    %(origin)s
    %(extra_arguments)s
    %(extra_keywords)s


def spline_filter1d(input, order=<NUM_LIT:3>, axis=-<NUM_LIT:1>, output=numpy.float64):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if order in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>output[...] = numpy.array(input)<EOL><DEDENT>else:<EOL><INDENT>axis = _ni_support._check_axis(axis, input.ndim)<EOL>_nd_image.spline_filter1d(input, order, axis, output)<EOL><DEDENT>return return_value<EOL>

Calculates a one-dimensional spline filter along the given axis.

The lines of the array along the given axis are filtered by a
spline filter. The order of the spline must be >= 2 and <= 5.

Parameters
----------
input : array_like
    The input array.
order : int, optional
    The order of the spline, default is 3.
axis : int, optional
    The axis along which the spline filter is applied. Default is the last
    axis.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array. Default is `numpy.float64`.

Returns
-------
spline_filter1d : ndarray or None
    The filtered input. If `output` is given as a parameter, None is
    returned.


def spline_filter(input, order=<NUM_LIT:3>, output=numpy.float64):

if order < <NUM_LIT:2> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>if order not in [<NUM_LIT:0>, <NUM_LIT:1>] and input.ndim > <NUM_LIT:0>:<EOL><INDENT>for axis in range(input.ndim):<EOL><INDENT>spline_filter1d(input, order, axis, output=output)<EOL>input = output<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[...] = input[...]<EOL><DEDENT>return return_value<EOL>

Multi-dimensional spline filter.

For more details, see `spline_filter1d`.

See Also
--------
spline_filter1d

Notes
-----
The multi-dimensional filter is implemented as a sequence of
one-dimensional spline filters. The intermediate arrays are stored
in the same data type as the output. Therefore, for output types
with a limited precision, the results may be imprecise because
intermediate results may be stored with insufficient precision.


def _geometric_transform(input, mapping, coordinates, matrix, offset, output,<EOL>order, mode, cval, extra_arguments, extra_keywords):

_nd_image.geometric_transform(<EOL>input, mapping, coordinates, matrix, offset, output,<EOL>order, mode, cval, extra_arguments, extra_keywords)<EOL>if output is not None and not output.dtype.isnative:<EOL><INDENT>output.byteswap(True)<EOL><DEDENT>return output<EOL>

Wrapper around _nd_image.geometric_transform to work around
endianness issues


def geometric_transform(input, mapping, output_shape=None,<EOL>output=None, order=<NUM_LIT:3>,<EOL>mode='<STR_LIT>', cval=<NUM_LIT:0.0>, prefilter=True,<EOL>extra_arguments=(), extra_keywords={}):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if output_shape is None:<EOL><INDENT>output_shape = input.shape<EOL><DEDENT>if input.ndim < <NUM_LIT:1> or len(output_shape) < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>mode = _extend_mode_to_code(mode)<EOL>if prefilter and order > <NUM_LIT:1>:<EOL><INDENT>filtered = spline_filter(input, order, output=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>filtered = input<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input,<EOL>shape=output_shape)<EOL>_geometric_transform(filtered, mapping, None, None, None, output,<EOL>order, mode, cval, extra_arguments, extra_keywords)<EOL>return return_value<EOL>

Apply an arbritrary geometric transform.

The given mapping function is used to find, for each point in the
output, the corresponding coordinates in the input. The value of the
input at those coordinates is determined by spline interpolation of
the requested order.

Parameters
----------
input : array_like
    The input array.
mapping : callable
    A callable object that accepts a tuple of length equal to the output
    array rank, and returns the corresponding input coordinates as a tuple
    of length equal to the input array rank.
output_shape : tuple of ints
    Shape tuple.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.
extra_arguments : tuple, optional
    Extra arguments passed to `mapping`.
extra_keywords : dict, optional
    Extra keywords passed to `mapping`.

Returns
-------
return_value : ndarray or None
    The filtered input. If `output` is given as a parameter, None is
    returned.

See Also
--------
map_coordinates, affine_transform, spline_filter1d

Examples
--------
>>> from scipy import ndimage
>>> a = np.arange(12.).reshape((4, 3))
>>> def shift_func(output_coords):
...     return (output_coords[0] - 0.5, output_coords[1] - 0.5)
...
>>> ndimage.geometric_transform(a, shift_func)
array([[ 0.   ,  0.   ,  0.   ],
       [ 0.   ,  1.362,  2.738],
       [ 0.   ,  4.812,  6.187],
       [ 0.   ,  8.263,  9.637]])


def map_coordinates(input, coordinates, output=None, order=<NUM_LIT:3>,<EOL>mode='<STR_LIT>', cval=<NUM_LIT:0.0>, prefilter=True):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>coordinates = numpy.asarray(coordinates)<EOL>if numpy.iscomplexobj(coordinates):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>output_shape = coordinates.shape[<NUM_LIT:1>:]<EOL>if input.ndim < <NUM_LIT:1> or len(output_shape) < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if coordinates.shape[<NUM_LIT:0>] != input.ndim:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>mode = _extend_mode_to_code(mode)<EOL>if prefilter and order > <NUM_LIT:1>:<EOL><INDENT>filtered = spline_filter(input, order, output=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>filtered = input<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input,<EOL>shape=output_shape)<EOL>_geometric_transform(filtered, None, coordinates, None, None,<EOL>output, order, mode, cval, None, None)<EOL>return return_value<EOL>

Map the input array to new coordinates by interpolation.

The array of coordinates is used to find, for each point in the output,
the corresponding coordinates in the input. The value of the input at
those coordinates is determined by spline interpolation of the
requested order.

The shape of the output is derived from that of the coordinate
array by dropping the first axis. The values of the array along
the first axis are the coordinates in the input array at which the
output value is found.

Parameters
----------
input : ndarray
    The input array.
coordinates : array_like
    The coordinates at which `input` is evaluated.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.

Returns
-------
map_coordinates : ndarray
    The result of transforming the input. The shape of the output is
    derived from that of `coordinates` by dropping the first axis.

See Also
--------
spline_filter, geometric_transform, scipy.interpolate

Examples
--------
>>> from scipy import ndimage
>>> a = np.arange(12.).reshape((4, 3))
>>> a
array([[  0.,   1.,   2.],
       [  3.,   4.,   5.],
       [  6.,   7.,   8.],
       [  9.,  10.,  11.]])
>>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
[ 2.  7.]

Above, the interpolated value of a[0.5, 0.5] gives output[0], while
a[2, 1] is output[1].

>>> inds = np.array([[0.5, 2], [0.5, 4]])
>>> ndimage.map_coordinates(a, inds, order=1, cval=-33.3)
array([  2. , -33.3])
>>> ndimage.map_coordinates(a, inds, order=1, mode='nearest')
array([ 2.,  8.])
>>> ndimage.map_coordinates(a, inds, order=1, cval=0, output=bool)
array([ True, False], dtype=bool


def affine_transform(input, matrix, offset=<NUM_LIT:0.0>, output_shape=None,<EOL>output=None, order=<NUM_LIT:3>,<EOL>mode='<STR_LIT>', cval=<NUM_LIT:0.0>, prefilter=True):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if output_shape is None:<EOL><INDENT>output_shape = input.shape<EOL><DEDENT>if input.ndim < <NUM_LIT:1> or len(output_shape) < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>mode = _extend_mode_to_code(mode)<EOL>if prefilter and order > <NUM_LIT:1>:<EOL><INDENT>filtered = spline_filter(input, order, output=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>filtered = input<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input,<EOL>shape=output_shape)<EOL>matrix = numpy.asarray(matrix, dtype=numpy.float64)<EOL>if matrix.ndim not in [<NUM_LIT:1>, <NUM_LIT:2>] or matrix.shape[<NUM_LIT:0>] < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if matrix.shape[<NUM_LIT:0>] != input.ndim:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if matrix.ndim == <NUM_LIT:2> and matrix.shape[<NUM_LIT:1>] != output.ndim:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if not matrix.flags.contiguous:<EOL><INDENT>matrix = matrix.copy()<EOL><DEDENT>offset = _ni_support._normalize_sequence(offset, input.ndim)<EOL>offset = numpy.asarray(offset, dtype=numpy.float64)<EOL>if offset.ndim != <NUM_LIT:1> or offset.shape[<NUM_LIT:0>] < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if not offset.flags.contiguous:<EOL><INDENT>offset = offset.copy()<EOL><DEDENT>if matrix.ndim == <NUM_LIT:1>:<EOL><INDENT>_nd_image.zoom_shift(filtered, matrix, offset, output, order,<EOL>mode, cval)<EOL><DEDENT>else:<EOL><INDENT>_geometric_transform(filtered, None, None, matrix, offset,<EOL>output, order, mode, cval, None, None)<EOL><DEDENT>return return_value<EOL>

Apply an affine transformation.

The given matrix and offset are used to find for each point in the
output the corresponding coordinates in the input by an affine
transformation. The value of the input at those coordinates is
determined by spline interpolation of the requested order. Points
outside the boundaries of the input are filled according to the given
mode.

Parameters
----------
input : ndarray
    The input array.
matrix : ndarray
    The matrix must be two-dimensional or can also be given as a
    one-dimensional sequence or array. In the latter case, it is assumed
    that the matrix is diagonal. A more efficient algorithms is then
    applied that exploits the separability of the problem.
offset : float or sequence, optional
    The offset into the array where the transform is applied. If a float,
    `offset` is the same for each axis. If a sequence, `offset` should
    contain one value for each axis.
output_shape : tuple of ints, optional
    Shape tuple.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.

Returns
-------
affine_transform : ndarray or None
    The transformed input. If `output` is given as a parameter, None is
    returned.


def shift(input, shift, output=None, order=<NUM_LIT:3>, mode='<STR_LIT>', cval=<NUM_LIT:0.0>,<EOL>prefilter=True):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if input.ndim < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>mode = _extend_mode_to_code(mode)<EOL>if prefilter and order > <NUM_LIT:1>:<EOL><INDENT>filtered = spline_filter(input, order, output=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>filtered = input<EOL><DEDENT>output, return_value = _ni_support._get_output(output, input)<EOL>shift = _ni_support._normalize_sequence(shift, input.ndim)<EOL>shift = [-ii for ii in shift]<EOL>shift = numpy.asarray(shift, dtype=numpy.float64)<EOL>if not shift.flags.contiguous:<EOL><INDENT>shift = shift.copy()<EOL><DEDENT>_nd_image.zoom_shift(filtered, None, shift, output, order, mode, cval)<EOL>return return_value<EOL>

Shift an array.

The array is shifted using spline interpolation of the requested order.
Points outside the boundaries of the input are filled according to the
given mode.

Parameters
----------
input : ndarray
    The input array.
shift : float or sequence, optional
    The shift along the axes. If a float, `shift` is the same for each
    axis. If a sequence, `shift` should contain one value for each axis.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.

Returns
-------
shift : ndarray or None
    The shifted input. If `output` is given as a parameter, None is
    returned.


def zoom(input, zoom, output=None, order=<NUM_LIT:3>, mode='<STR_LIT>', cval=<NUM_LIT:0.0>,<EOL>prefilter=True):

if order < <NUM_LIT:0> or order > <NUM_LIT:5>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>input = numpy.asarray(input)<EOL>if numpy.iscomplexobj(input):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if input.ndim < <NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>mode = _extend_mode_to_code(mode)<EOL>if prefilter and order > <NUM_LIT:1>:<EOL><INDENT>filtered = spline_filter(input, order, output=numpy.float64)<EOL><DEDENT>else:<EOL><INDENT>filtered = input<EOL><DEDENT>zoom = _ni_support._normalize_sequence(zoom, input.ndim)<EOL>output_shape = tuple(<EOL>[int(round(ii * jj)) for ii, jj in zip(input.shape, zoom)])<EOL>output_shape_old = tuple(<EOL>[int(ii * jj) for ii, jj in zip(input.shape, zoom)])<EOL>if output_shape != output_shape_old:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", UserWarning)<EOL><DEDENT>zoom_div = numpy.array(output_shape, float) - <NUM_LIT:1><EOL>zoom = (numpy.array(input.shape) - <NUM_LIT:1>) / zoom_div<EOL>zoom[~numpy.isfinite(zoom)] = <NUM_LIT:1><EOL>output, return_value = _ni_support._get_output(output, input,<EOL>shape=output_shape)<EOL>zoom = numpy.asarray(zoom, dtype=numpy.float64)<EOL>zoom = numpy.ascontiguousarray(zoom)<EOL>_nd_image.zoom_shift(filtered, zoom, None, output, order, mode, cval)<EOL>return return_value<EOL>

Zoom an array.

The array is zoomed using spline interpolation of the requested order.

Parameters
----------
input : ndarray
    The input array.
zoom : float or sequence, optional
    The zoom factor along the axes. If a float, `zoom` is the same for each
    axis. If a sequence, `zoom` should contain one value for each axis.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.

Returns
-------
zoom : ndarray or None
    The zoomed input. If `output` is given as a parameter, None is
    returned.


def rotate(input, angle, axes=(<NUM_LIT:1>, <NUM_LIT:0>), reshape=True,<EOL>output=None, order=<NUM_LIT:3>,<EOL>mode='<STR_LIT>', cval=<NUM_LIT:0.0>, prefilter=True):

input = numpy.asarray(input)<EOL>axes = list(axes)<EOL>rank = input.ndim<EOL>if axes[<NUM_LIT:0>] < <NUM_LIT:0>:<EOL><INDENT>axes[<NUM_LIT:0>] += rank<EOL><DEDENT>if axes[<NUM_LIT:1>] < <NUM_LIT:0>:<EOL><INDENT>axes[<NUM_LIT:1>] += rank<EOL><DEDENT>if axes[<NUM_LIT:0>] < <NUM_LIT:0> or axes[<NUM_LIT:1>] < <NUM_LIT:0> or axes[<NUM_LIT:0>] > rank or axes[<NUM_LIT:1>] > rank:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if axes[<NUM_LIT:0>] > axes[<NUM_LIT:1>]:<EOL><INDENT>axes = axes[<NUM_LIT:1>], axes[<NUM_LIT:0>]<EOL><DEDENT>angle = numpy.pi / <NUM_LIT> * angle<EOL>m11 = math.cos(angle)<EOL>m12 = math.sin(angle)<EOL>m21 = -math.sin(angle)<EOL>m22 = math.cos(angle)<EOL>matrix = numpy.array([[m11, m12],<EOL>[m21, m22]], dtype=numpy.float64)<EOL>iy = input.shape[axes[<NUM_LIT:0>]]<EOL>ix = input.shape[axes[<NUM_LIT:1>]]<EOL>if reshape:<EOL><INDENT>mtrx = numpy.array([[m11, -m21],<EOL>[-m12, m22]], dtype=numpy.float64)<EOL>minc = [<NUM_LIT:0>, <NUM_LIT:0>]<EOL>maxc = [<NUM_LIT:0>, <NUM_LIT:0>]<EOL>coor = numpy.dot(mtrx, [<NUM_LIT:0>, ix])<EOL>minc, maxc = _minmax(coor, minc, maxc)<EOL>coor = numpy.dot(mtrx, [iy, <NUM_LIT:0>])<EOL>minc, maxc = _minmax(coor, minc, maxc)<EOL>coor = numpy.dot(mtrx, [iy, ix])<EOL>minc, maxc = _minmax(coor, minc, maxc)<EOL>oy = int(maxc[<NUM_LIT:0>] - minc[<NUM_LIT:0>] + <NUM_LIT:0.5>)<EOL>ox = int(maxc[<NUM_LIT:1>] - minc[<NUM_LIT:1>] + <NUM_LIT:0.5>)<EOL><DEDENT>else:<EOL><INDENT>oy = input.shape[axes[<NUM_LIT:0>]]<EOL>ox = input.shape[axes[<NUM_LIT:1>]]<EOL><DEDENT>offset = numpy.zeros((<NUM_LIT:2>,), dtype=numpy.float64)<EOL>offset[<NUM_LIT:0>] = float(oy) / <NUM_LIT> - <NUM_LIT:0.5><EOL>offset[<NUM_LIT:1>] = float(ox) / <NUM_LIT> - <NUM_LIT:0.5><EOL>offset = numpy.dot(matrix, offset)<EOL>tmp = numpy.zeros((<NUM_LIT:2>,), dtype=numpy.float64)<EOL>tmp[<NUM_LIT:0>] = float(iy) / <NUM_LIT> - <NUM_LIT:0.5><EOL>tmp[<NUM_LIT:1>] = float(ix) / <NUM_LIT> - <NUM_LIT:0.5><EOL>offset = tmp - offset<EOL>output_shape = list(input.shape)<EOL>output_shape[axes[<NUM_LIT:0>]] = oy<EOL>output_shape[axes[<NUM_LIT:1>]] = ox<EOL>output_shape = tuple(output_shape)<EOL>output, return_value = _ni_support._get_output(output, input,<EOL>shape=output_shape)<EOL>if input.ndim <= <NUM_LIT:2>:<EOL><INDENT>affine_transform(input, matrix, offset, output_shape, output,<EOL>order, mode, cval, prefilter)<EOL><DEDENT>else:<EOL><INDENT>coordinates = []<EOL>size = numpy.product(input.shape,axis=<NUM_LIT:0>)<EOL>size //= input.shape[axes[<NUM_LIT:0>]]<EOL>size //= input.shape[axes[<NUM_LIT:1>]]<EOL>for ii in range(input.ndim):<EOL><INDENT>if ii not in axes:<EOL><INDENT>coordinates.append(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>coordinates.append(slice(None, None, None))<EOL><DEDENT><DEDENT>iter_axes = list(range(input.ndim))<EOL>iter_axes.reverse()<EOL>iter_axes.remove(axes[<NUM_LIT:0>])<EOL>iter_axes.remove(axes[<NUM_LIT:1>])<EOL>os = (output_shape[axes[<NUM_LIT:0>]], output_shape[axes[<NUM_LIT:1>]])<EOL>for ii in range(size):<EOL><INDENT>ia = input[tuple(coordinates)]<EOL>oa = output[tuple(coordinates)]<EOL>affine_transform(ia, matrix, offset, os, oa, order, mode,<EOL>cval, prefilter)<EOL>for jj in iter_axes:<EOL><INDENT>if coordinates[jj] < input.shape[jj] - <NUM_LIT:1>:<EOL><INDENT>coordinates[jj] += <NUM_LIT:1><EOL>break<EOL><DEDENT>else:<EOL><INDENT>coordinates[jj] = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT><DEDENT>return return_value<EOL>

Rotate an array.

The array is rotated in the plane defined by the two axes given by the
`axes` parameter using spline interpolation of the requested order.

Parameters
----------
input : ndarray
    The input array.
angle : float
    The rotation angle in degrees.
axes : tuple of 2 ints, optional
    The two axes that define the plane of rotation. Default is the first
    two axes.
reshape : bool, optional
    If `reshape` is true, the output shape is adapted so that the input
    array is contained completely in the output. Default is True.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array.
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
mode : str, optional
    Points outside the boundaries of the input are filled according
    to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
    Default is 'constant'.
cval : scalar, optional
    Value used for points outside the boundaries of the input if
    ``mode='constant'``. Default is 0.0
prefilter : bool, optional
    The parameter prefilter determines if the input is pre-filtered with
    `spline_filter` before interpolation (necessary for spline
    interpolation of order > 1).  If False, it is assumed that the input is
    already filtered. Default is True.

Returns
-------
rotate : ndarray or None
    The rotated input. If `output` is given as a parameter, None is
    returned.


if mode == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:2><EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:3><EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:4><EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>

Convert an extension mode to the corresponding integer code.


def _normalize_sequence(input, rank, array_type=None):

if isinstance(input, integer_types + (float,)):<EOL><INDENT>normalized = [input] * rank<EOL><DEDENT>else:<EOL><INDENT>normalized = list(input)<EOL>if len(normalized) != rank:<EOL><INDENT>err = "<STR_LIT>"<EOL>raise RuntimeError(err)<EOL><DEDENT><DEDENT>return normalized<EOL>

If input is a scalar, create a sequence of length equal to the
    rank by duplicating the input. If input is a sequence,
    check if its length is equal to the length of array.


def iterate_structure(structure, iterations, origin=None):

structure = numpy.asarray(structure)<EOL>if iterations < <NUM_LIT:2>:<EOL><INDENT>return structure.copy()<EOL><DEDENT>ni = iterations - <NUM_LIT:1><EOL>shape = [ii + ni * (ii - <NUM_LIT:1>) for ii in structure.shape]<EOL>pos = [ni * (structure.shape[ii] // <NUM_LIT:2>) for ii in range(len(shape))]<EOL>slc = [slice(pos[ii], pos[ii] + structure.shape[ii], None)<EOL>for ii in range(len(shape))]<EOL>out = numpy.zeros(shape, bool)<EOL>out[slc] = structure != <NUM_LIT:0><EOL>out = binary_dilation(out, structure, iterations=ni)<EOL>if origin is None:<EOL><INDENT>return out<EOL><DEDENT>else:<EOL><INDENT>origin = _ni_support._normalize_sequence(origin, structure.ndim)<EOL>origin = [iterations * o for o in origin]<EOL>return out, origin<EOL><DEDENT>

Iterate a structure by dilating it with itself.

Parameters
----------
structure : array_like
   Structuring element (an array of bools, for example), to be dilated with
   itself.
iterations : int
   number of dilations performed on the structure with itself
origin : optional
    If origin is None, only the iterated structure is returned. If
    not, a tuple of the iterated structure and the modified origin is
    returned.

Returns
-------
iterate_structure : ndarray of bools
    A new structuring element obtained by dilating `structure`
    (`iterations` - 1) times with itself.

See also
--------
generate_binary_structure

Examples
--------
>>> struct = ndimage.generate_binary_structure(2, 1)
>>> struct.astype(int)
array([[0, 1, 0],
       [1, 1, 1],
       [0, 1, 0]])
>>> ndimage.iterate_structure(struct, 2).astype(int)
array([[0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1],
       [0, 1, 1, 1, 0],
       [0, 0, 1, 0, 0]])
>>> ndimage.iterate_structure(struct, 3).astype(int)
array([[0, 0, 0, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0]])


if connectivity < <NUM_LIT:1>:<EOL><INDENT>connectivity = <NUM_LIT:1><EOL><DEDENT>if rank < <NUM_LIT:1>:<EOL><INDENT>if connectivity < <NUM_LIT:1>:<EOL><INDENT>return numpy.array(<NUM_LIT:0>, dtype=bool)<EOL><DEDENT>else:<EOL><INDENT>return numpy.array(<NUM_LIT:1>, dtype=bool)<EOL><DEDENT><DEDENT>output = numpy.fabs(numpy.indices([<NUM_LIT:3>] * rank) - <NUM_LIT:1>)<EOL>output = numpy.add.reduce(output, <NUM_LIT:0>)<EOL>return numpy.asarray(output <= connectivity, dtype=bool)<EOL>

Generate a binary structure for binary morphological operations.

Parameters
----------
rank : int
     Number of dimensions of the array to which the structuring element
     will be applied, as returned by `np.ndim`.
connectivity : int
     `connectivity` determines which elements of the output array belong
     to the structure, i.e. are considered as neighbors of the central
     element. Elements up to a squared distance of `connectivity` from
     the center are considered neighbors. `connectivity` may range from 1
     (no diagonal elements are neighbors) to `rank` (all elements are
     neighbors).

Returns
-------
output : ndarray of bools
     Structuring element which may be used for binary morphological
     operations, with `rank` dimensions and all dimensions equal to 3.

See also
--------
iterate_structure, binary_dilation, binary_erosion

Notes
-----
`generate_binary_structure` can only create structuring elements with
dimensions equal to 3, i.e. minimal dimensions. For larger structuring
elements, that are useful e.g. for eroding large objects, one may either
use   `iterate_structure`, or create directly custom arrays with
numpy functions such as `numpy.ones`.

Examples
--------
>>> struct = ndimage.generate_binary_structure(2, 1)
>>> struct
array([[False,  True, False],
       [ True,  True,  True],
       [False,  True, False]], dtype=bool)
>>> a = np.zeros((5,5))
>>> a[2, 2] = 1
>>> a
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> b = ndimage.binary_dilation(a, structure=struct).astype(a.dtype)
>>> b
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> ndimage.binary_dilation(b, structure=struct).astype(a.dtype)
array([[ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.]])
>>> struct = ndimage.generate_binary_structure(2, 2)
>>> struct
array([[ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True]], dtype=bool)
>>> struct = ndimage.generate_binary_structure(3, 1)
>>> struct # no diagonal elements
array([[[False, False, False],
        [False,  True, False],
        [False, False, False]],
       [[False,  True, False],
        [ True,  True,  True],
        [False,  True, False]],
       [[False, False, False],
        [False,  True, False],
        [False, False, False]]], dtype=bool)


def binary_erosion(input, structure=None, iterations=<NUM_LIT:1>, mask=None,<EOL>output=None, border_value=<NUM_LIT:0>, origin=<NUM_LIT:0>, brute_force=False):

return _binary_erosion(input, structure, iterations, mask,<EOL>output, border_value, origin, <NUM_LIT:0>, brute_force)<EOL>

Multi-dimensional binary erosion with a given structuring element.

Binary erosion is a mathematical morphology operation used for image
processing.

Parameters
----------
input : array_like
    Binary image to be eroded. Non-zero (True) elements form
    the subset to be eroded.
structure : array_like, optional
    Structuring element used for the erosion. Non-zero elements are
    considered True. If no structuring element is provided, an element
    is generated with a square connectivity equal to one.
iterations : {int, float}, optional
    The erosion is repeated `iterations` times (one, by default).
    If iterations is less than 1, the erosion is repeated until the
    result does not change anymore.
mask : array_like, optional
    If a mask is given, only those elements with a True value at
    the corresponding mask element are modified at each iteration.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int or tuple of ints, optional
    Placement of the filter, by default 0.
border_value : int (cast to 0 or 1)
    Value at the border in the output array.

Returns
-------
binary_erosion : ndarray of bools
    Erosion of the input by the structuring element.

See also
--------
grey_erosion, binary_dilation, binary_closing, binary_opening,
generate_binary_structure

Notes
-----
Erosion [1]_ is a mathematical morphology operation [2]_ that uses a
structuring element for shrinking the shapes in an image. The binary
erosion of an image by a structuring element is the locus of the points
where a superimposition of the structuring element centered on the point
is entirely contained in the set of non-zero elements of the image.

References
----------
.. [1] http://en.wikipedia.org/wiki/Erosion_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[1:6, 2:5] = 1
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.binary_erosion(a).astype(a.dtype)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> #Erosion removes objects smaller than the structure
>>> ndimage.binary_erosion(a, structure=np.ones((5,5))).astype(a.dtype)
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, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])


def binary_dilation(input, structure=None, iterations=<NUM_LIT:1>, mask=None,<EOL>output=None, border_value=<NUM_LIT:0>, origin=<NUM_LIT:0>, brute_force=False):

input = numpy.asarray(input)<EOL>if structure is None:<EOL><INDENT>structure = generate_binary_structure(input.ndim, <NUM_LIT:1>)<EOL><DEDENT>origin = _ni_support._normalize_sequence(origin, input.ndim)<EOL>structure = numpy.asarray(structure)<EOL>structure = structure[tuple([slice(None, None, -<NUM_LIT:1>)] *<EOL>structure.ndim)]<EOL>for ii in range(len(origin)):<EOL><INDENT>origin[ii] = -origin[ii]<EOL>if not structure.shape[ii] & <NUM_LIT:1>:<EOL><INDENT>origin[ii] -= <NUM_LIT:1><EOL><DEDENT><DEDENT>return _binary_erosion(input, structure, iterations, mask,<EOL>output, border_value, origin, <NUM_LIT:1>, brute_force)<EOL>

Multi-dimensional binary dilation with the given structuring element.

Parameters
----------
input : array_like
    Binary array_like to be dilated. Non-zero (True) elements form
    the subset to be dilated.
structure : array_like, optional
    Structuring element used for the dilation. Non-zero elements are
    considered True. If no structuring element is provided an element
    is generated with a square connectivity equal to one.
iterations : {int, float}, optional
    The dilation is repeated `iterations` times (one, by default).
    If iterations is less than 1, the dilation is repeated until the
    result does not change anymore.
mask : array_like, optional
    If a mask is given, only those elements with a True value at
    the corresponding mask element are modified at each iteration.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int or tuple of ints, optional
    Placement of the filter, by default 0.
border_value : int (cast to 0 or 1)
    Value at the border in the output array.

Returns
-------
binary_dilation : ndarray of bools
    Dilation of the input by the structuring element.

See also
--------
grey_dilation, binary_erosion, binary_closing, binary_opening,
generate_binary_structure

Notes
-----
Dilation [1]_ is a mathematical morphology operation [2]_ that uses a
structuring element for expanding the shapes in an image. The binary
dilation of an image by a structuring element is the locus of the points
covered by the structuring element, when its center lies within the
non-zero points of the image.

References
----------
.. [1] http://en.wikipedia.org/wiki/Dilation_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((5, 5))
>>> a[2, 2] = 1
>>> a
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> ndimage.binary_dilation(a)
array([[False, False, False, False, False],
       [False, False,  True, False, False],
       [False,  True,  True,  True, False],
       [False, False,  True, False, False],
       [False, False, False, False, False]], dtype=bool)
>>> ndimage.binary_dilation(a).astype(a.dtype)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> # 3x3 structuring element with connectivity 1, used by default
>>> struct1 = ndimage.generate_binary_structure(2, 1)
>>> struct1
array([[False,  True, False],
       [ True,  True,  True],
       [False,  True, False]], dtype=bool)
>>> # 3x3 structuring element with connectivity 2
>>> struct2 = ndimage.generate_binary_structure(2, 2)
>>> struct2
array([[ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True]], dtype=bool)
>>> ndimage.binary_dilation(a, structure=struct1).astype(a.dtype)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> ndimage.binary_dilation(a, structure=struct2).astype(a.dtype)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> ndimage.binary_dilation(a, structure=struct1,\\
... iterations=2).astype(a.dtype)
array([[ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 0.,  1.,  1.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.]])


def binary_opening(input, structure=None, iterations=<NUM_LIT:1>, output=None,<EOL>origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if structure is None:<EOL><INDENT>rank = input.ndim<EOL>structure = generate_binary_structure(rank, <NUM_LIT:1>)<EOL><DEDENT>tmp = binary_erosion(input, structure, iterations, None, None, <NUM_LIT:0>,<EOL>origin)<EOL>return binary_dilation(tmp, structure, iterations, None, output, <NUM_LIT:0>,<EOL>origin)<EOL>

Multi-dimensional binary opening with the given structuring element.

The *opening* of an input image by a structuring element is the
*dilation* of the *erosion* of the image by the structuring element.

Parameters
----------
input : array_like
    Binary array_like to be opened. Non-zero (True) elements form
    the subset to be opened.
structure : array_like, optional
    Structuring element used for the opening. Non-zero elements are
    considered True. If no structuring element is provided an element
    is generated with a square connectivity equal to one (i.e., only
    nearest neighbors are connected to the center, diagonally-connected
    elements are not considered neighbors).
iterations : {int, float}, optional
    The erosion step of the opening, then the dilation step are each
    repeated `iterations` times (one, by default). If `iterations` is
    less than 1, each operation is repeated until the result does
    not change anymore.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int or tuple of ints, optional
    Placement of the filter, by default 0.

Returns
-------
binary_opening : ndarray of bools
    Opening of the input by the structuring element.

See also
--------
grey_opening, binary_closing, binary_erosion, binary_dilation,
generate_binary_structure

Notes
-----
*Opening* [1]_ is a mathematical morphology operation [2]_ that
consists in the succession of an erosion and a dilation of the
input with the same structuring element. Opening therefore removes
objects smaller than the structuring element.

Together with *closing* (`binary_closing`), opening can be used for
noise removal.

References
----------
.. [1] http://en.wikipedia.org/wiki/Opening_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((5,5), dtype=np.int)
>>> a[1:4, 1:4] = 1; a[4, 4] = 1
>>> a
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 1]])
>>> # Opening removes small objects
>>> ndimage.binary_opening(a, structure=np.ones((3,3))).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> # Opening can also smooth corners
>>> ndimage.binary_opening(a).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0]])
>>> # Opening is the dilation of the erosion of the input
>>> ndimage.binary_erosion(a).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]])
>>> ndimage.binary_dilation(ndimage.binary_erosion(a)).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0]])


def binary_closing(input, structure=None, iterations=<NUM_LIT:1>, output=None,<EOL>origin=<NUM_LIT:0>):

input = numpy.asarray(input)<EOL>if structure is None:<EOL><INDENT>rank = input.ndim<EOL>structure = generate_binary_structure(rank, <NUM_LIT:1>)<EOL><DEDENT>tmp = binary_dilation(input, structure, iterations, None, None, <NUM_LIT:0>,<EOL>origin)<EOL>return binary_erosion(tmp, structure, iterations, None, output, <NUM_LIT:0>,<EOL>origin)<EOL>

Multi-dimensional binary closing with the given structuring element.

The *closing* of an input image by a structuring element is the
*erosion* of the *dilation* of the image by the structuring element.

Parameters
----------
input : array_like
    Binary array_like to be closed. Non-zero (True) elements form
    the subset to be closed.
structure : array_like, optional
    Structuring element used for the closing. Non-zero elements are
    considered True. If no structuring element is provided an element
    is generated with a square connectivity equal to one (i.e., only
    nearest neighbors are connected to the center, diagonally-connected
    elements are not considered neighbors).
iterations : {int, float}, optional
    The dilation step of the closing, then the erosion step are each
    repeated `iterations` times (one, by default). If iterations is
    less than 1, each operations is repeated until the result does
    not change anymore.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int or tuple of ints, optional
    Placement of the filter, by default 0.

Returns
-------
binary_closing : ndarray of bools
    Closing of the input by the structuring element.

See also
--------
grey_closing, binary_opening, binary_dilation, binary_erosion,
generate_binary_structure

Notes
-----
*Closing* [1]_ is a mathematical morphology operation [2]_ that
consists in the succession of a dilation and an erosion of the
input with the same structuring element. Closing therefore fills
holes smaller than the structuring element.

Together with *opening* (`binary_opening`), closing can be used for
noise removal.

References
----------
.. [1] http://en.wikipedia.org/wiki/Closing_%28morphology%29
.. [2] http://en.wikipedia.org/wiki/Mathematical_morphology

Examples
--------
>>> a = np.zeros((5,5), dtype=np.int)
>>> a[1:-1, 1:-1] = 1; a[2,2] = 0
>>> a
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> # Closing removes small holes
>>> ndimage.binary_closing(a).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> # Closing is the erosion of the dilation of the input
>>> ndimage.binary_dilation(a).astype(np.int)
array([[0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [0, 1, 1, 1, 0]])
>>> ndimage.binary_erosion(ndimage.binary_dilation(a)).astype(np.int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])

>>> a = np.zeros((7,7), dtype=np.int)
>>> a[1:6, 2:5] = 1; a[1:3,3] = 0
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> # In addition to removing holes, closing can also
>>> # coarsen boundaries with fine hollows.
>>> ndimage.binary_closing(a).astype(np.int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.binary_closing(a, structure=np.ones((2,2))).astype(np.int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])


def binary_hit_or_miss(input, structure1=None, structure2=None,<EOL>output=None, origin1=<NUM_LIT:0>, origin2=None):

input = numpy.asarray(input)<EOL>if structure1 is None:<EOL><INDENT>structure1 = generate_binary_structure(input.ndim, <NUM_LIT:1>)<EOL><DEDENT>if structure2 is None:<EOL><INDENT>structure2 = numpy.logical_not(structure1)<EOL><DEDENT>origin1 = _ni_support._normalize_sequence(origin1, input.ndim)<EOL>if origin2 is None:<EOL><INDENT>origin2 = origin1<EOL><DEDENT>else:<EOL><INDENT>origin2 = _ni_support._normalize_sequence(origin2, input.ndim)<EOL><DEDENT>tmp1 = _binary_erosion(input, structure1, <NUM_LIT:1>, None, None, <NUM_LIT:0>, origin1,<EOL><NUM_LIT:0>, False)<EOL>inplace = isinstance(output, numpy.ndarray)<EOL>result = _binary_erosion(input, structure2, <NUM_LIT:1>, None, output, <NUM_LIT:0>,<EOL>origin2, <NUM_LIT:1>, False)<EOL>if inplace:<EOL><INDENT>numpy.logical_not(output, output)<EOL>numpy.logical_and(tmp1, output, output)<EOL><DEDENT>else:<EOL><INDENT>numpy.logical_not(result, result)<EOL>return numpy.logical_and(tmp1, result)<EOL><DEDENT>

Multi-dimensional binary hit-or-miss transform.

The hit-or-miss transform finds the locations of a given pattern
inside the input image.

Parameters
----------
input : array_like (cast to booleans)
    Binary image where a pattern is to be detected.
structure1 : array_like (cast to booleans), optional
    Part of the structuring element to be fitted to the foreground
    (non-zero elements) of `input`. If no value is provided, a
    structure of square connectivity 1 is chosen.
structure2 : array_like (cast to booleans), optional
    Second part of the structuring element that has to miss completely
    the foreground. If no value is provided, the complementary of
    `structure1` is taken.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin1 : int or tuple of ints, optional
    Placement of the first part of the structuring element `structure1`,
    by default 0 for a centered structure.
origin2 : int or tuple of ints, optional
    Placement of the second part of the structuring element `structure2`,
    by default 0 for a centered structure. If a value is provided for
    `origin1` and not for `origin2`, then `origin2` is set to `origin1`.

Returns
-------
binary_hit_or_miss : ndarray
    Hit-or-miss transform of `input` with the given structuring
    element (`structure1`, `structure2`).

See also
--------
ndimage.morphology, binary_erosion

References
----------
.. [1] http://en.wikipedia.org/wiki/Hit-or-miss_transform

Examples
--------
>>> a = np.zeros((7,7), dtype=np.int)
>>> a[1, 1] = 1; a[2:4, 2:4] = 1; a[4:6, 4:6] = 1
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 0, 0, 0],
       [0, 0, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> structure1 = np.array([[1, 0, 0], [0, 1, 1], [0, 1, 1]])
>>> structure1
array([[1, 0, 0],
       [0, 1, 1],
       [0, 1, 1]])
>>> # Find the matches of structure1 in the array a
>>> ndimage.binary_hit_or_miss(a, structure1=structure1).astype(np.int)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> # Change the origin of the filter
>>> # origin1=1 is equivalent to origin1=(1,1) here
>>> ndimage.binary_hit_or_miss(a, structure1=structure1,\\
... origin1=1).astype(np.int)
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, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0]])


def binary_propagation(input, structure=None, mask=None,<EOL>output=None, border_value=<NUM_LIT:0>, origin=<NUM_LIT:0>):

return binary_dilation(input, structure, -<NUM_LIT:1>, mask, output,<EOL>border_value, origin)<EOL>

Multi-dimensional binary propagation with the given structuring element.

Parameters
----------
input : array_like
    Binary image to be propagated inside `mask`.
structure : array_like
    Structuring element used in the successive dilations. The output
    may depend on the structuring element, especially if `mask` has
    several connex components. If no structuring element is
    provided, an element is generated with a squared connectivity equal
    to one.
mask : array_like
    Binary mask defining the region into which `input` is allowed to
    propagate.
output : ndarray, optional
    Array of the same shape as input, into which the output is placed.
    By default, a new array is created.
origin : int or tuple of ints, optional
    Placement of the filter, by default 0.

Returns
-------
binary_propagation : ndarray
    Binary propagation of `input` inside `mask`.

Notes
-----
This function is functionally equivalent to calling binary_dilation
with the number of iterations less then one: iterative dilation until
the result does not change anymore.

The succession of an erosion and propagation inside the original image
can be used instead of an *opening* for deleting small objects while
keeping the contours of larger objects untouched.

References
----------
.. [1] http://cmm.ensmp.fr/~serra/cours/pdf/en/ch6en.pdf, slide 15.
.. [2] http://www.qi.tnw.tudelft.nl/Courses/FIP/noframes/fip-Morpholo.html#Heading102

Examples
--------
>>> input = np.zeros((8, 8), dtype=np.int)
>>> input[2, 2] = 1
>>> mask = np.zeros((8, 8), dtype=np.int)
>>> mask[1:4, 1:4] = mask[4, 4]  = mask[6:8, 6:8] = 1
>>> input
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 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, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]])
>>> mask
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 0, 1, 1]])
>>> ndimage.binary_propagation(input, mask=mask).astype(np.int)
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 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, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.binary_propagation(input, mask=mask,\\
... structure=np.ones((3,3))).astype(np.int)
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 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, 0, 0]])

>>> # Comparison between opening and erosion+propagation
>>> a = np.zeros((6,6), dtype=np.int)
>>> a[2:5, 2:5] = 1; a[0, 0] = 1; a[5, 5] = 1
>>> a
array([[1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 1]])
>>> ndimage.binary_opening(a).astype(np.int)
array([[0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0]])
>>> b = ndimage.binary_erosion(a)
>>> b.astype(int)
array([[0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0]])
>>> ndimage.binary_propagation(b, mask=a).astype(np.int)
array([[0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0]])