[Scipy-svn] r6888 - trunk/scipy/ndimage

scipy-svn@scip... scipy-svn@scip...
Sun Nov 14 04:00:16 CST 2010


Author: rgommers
Date: 2010-11-14 04:00:16 -0600 (Sun, 14 Nov 2010)
New Revision: 6888

Modified:
   trunk/scipy/ndimage/__init__.py
   trunk/scipy/ndimage/filters.py
   trunk/scipy/ndimage/measurements.py
Log:
DOC: merge more wiki edits for ndimage module.

Modified: trunk/scipy/ndimage/__init__.py
===================================================================
--- trunk/scipy/ndimage/__init__.py	2010-11-14 09:59:58 UTC (rev 6887)
+++ trunk/scipy/ndimage/__init__.py	2010-11-14 10:00:16 UTC (rev 6888)
@@ -1,3 +1,70 @@
+"""
+N-dimensional image package
+===========================
+
+This package contains various functions for multi-dimensional image
+processing.
+
+Modules
+-------
+
+.. autosummary::
+   :toctree: generated/
+
+   filters -
+   fourier -
+   interpolation -
+   io -
+   measurements -
+   morphology -
+
+Functions (partial list)
+------------------------
+
+.. autosummary::
+   :toctree: generated/
+
+   affine_transform - Apply an affine transformation
+   center_of_mass - The center of mass of the values of an array at labels
+   convolve - Multi-dimensional convolution
+   convolve1d - 1-D convolution along the given axis
+   correlate - Multi-dimensional correlation
+   correlate1d - 1-D correlation along the given axis
+   extrema - Min's and max's of an array at labels, with their positions
+   find_objects - Find objects in a labeled array
+   generic_filter - Multi-dimensional filter using a given function
+   generic_filter1d - 1-D generic filter along the given axis
+   geometric_transform - Apply an arbritrary geometric transform
+   histogram - Histogram of the values of an array, optionally at labels
+   imread - Load an image from a file
+   label - Label features in an array
+   laplace - n-D Laplace filter based on approximate second derivatives
+   map_coordinates - Map input array to new coordinates by interpolation
+   mean - Mean of the values of an array at labels
+   median_filter - Calculates a multi-dimensional median filter
+   percentile_filter - Calculates a multi-dimensional percentile filter
+   rank_filter - Calculates a multi-dimensional rank filter
+   rotate - Rotate an array
+   shift - Shift an array
+   standard_deviation - Standard deviation of an n-D image array
+   sum - Sum of the values of the array
+   uniform_filter - Multi-dimensional uniform filter
+   uniform_filter1d - 1-D uniform filter along the given axis
+   variance - Variance of the values of an n-D image array
+   zoom - Zoom an array
+
+Note: the above is only roughly half the functions available in this
+package
+
+Objects
+-------
+
+.. autosummary::
+   :toctree: generated/
+
+   docdict -
+
+"""
 # Copyright (C) 2003-2005 Peter J. Verveer
 #
 # Redistribution and use in source and binary forms, with or without

Modified: trunk/scipy/ndimage/filters.py
===================================================================
--- trunk/scipy/ndimage/filters.py	2010-11-14 09:59:58 UTC (rev 6887)
+++ trunk/scipy/ndimage/filters.py	2010-11-14 10:00:16 UTC (rev 6888)
@@ -543,29 +543,104 @@
 
     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
+    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, where ``cval`` is the value when mode is equal to
-        'constant'. Default is 'reflect'
+        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
+        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
+        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]])
+    >>> b = 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]])
+    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]])
+
     """
     return _correlate_or_convolve(input, weights, output, mode, cval,
                                   origin, True)

Modified: trunk/scipy/ndimage/measurements.py
===================================================================
--- trunk/scipy/ndimage/measurements.py	2010-11-14 09:59:58 UTC (rev 6887)
+++ trunk/scipy/ndimage/measurements.py	2010-11-14 10:00:16 UTC (rev 6888)
@@ -75,8 +75,8 @@
         An array-like object where each unique feature has a unique value
 
     num_features : int
+        How many objects were found
 
-
     If `output` is None or a data type, this function returns a tuple,
     (`labeled_array`, `num_features`).
 
@@ -486,13 +486,52 @@
     return sum
 
 def mean(input, labels = None, index = None):
-    """Calculate the mean of the values of an array at labels.
+    """
+    Calculate the mean of the values of an array at labels.
 
-    Labels must be None or an array that can be broadcast to the input.
+    Parameters
+    ----------
+    input : array_like
+        Array on which to compute the mean of elements over distinct
+        regions.
+    labels : array_like, optional
+        Array of labels of same shape, or broadcastable to the same shape as
+        `input`. All elements sharing the same label form one region over
+        which the mean of the elements is computed.
+    index : int or sequence of ints, optional
+        Labels of the objects over which the mean is to be computed.
+        Default is None, in which case the mean for all values where label is
+        greater than 0 is calculated.
 
-    Index must be None, a single label or sequence of labels.  If
-    None, the mean for all values where label is greater than 0 is
-    calculated.
+    Returns
+    -------
+    out : list
+        Sequence of same length as ``index``, with the mean of the different
+        regions labeled by the labels in ``index``.
+
+    See also
+    --------
+    ndimage.variance, ndimage.standard_deviation, ndimage.minimum,
+    ndimage.maximum, ndimage.sum
+    ndimage.label
+
+    Examples
+    --------
+    >>> a = np.arange(25).reshape((5,5))
+    >>> labels = np.zeros_like(a)
+    >>> labels[3:5,3:5] = 1
+    >>> index = np.unique(labels)
+    >>> labels
+    array([[0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0],
+           [0, 0, 0, 0, 0],
+           [0, 0, 0, 1, 1],
+           [0, 0, 0, 1, 1]])
+    >>> index
+    array([0, 1])
+    >>> ndimage.mean(a, labels=labels, index=index)
+    [10.285714285714286, 21.0]
+
     """
 
     count, sum = _stats(input, labels, index)
@@ -693,17 +732,17 @@
     Parameters
     ----------
 
-    input: array-like
-        Array-like of values. For each region specified by `labels`, the
+    input: array_like
+        Array_like of values. For each region specified by `labels`, the
         minimal values of `input` over the region is computed.
 
-    labels: array-like, optional
-        An array-like of integers marking different regions over which the
+    labels: array_like, optional
+        An array_like of integers marking different regions over which the
         minimum value of `input` is to be computed. `labels` must have the
         same shape as `input`. If `labels` is not specified, the minimum
         over the whole array is returned.
 
-    index: array-like, optional
+    index: array_like, optional
         A list of region labels that are taken into account for computing the
         minima. If index is None, the minimum over all elements where `labels`
         is non-zero is returned.



More information about the Scipy-svn mailing list