diff --git a/skimage/exposure/exposure.py b/skimage/exposure/exposure.py index c7f1e712..6f2066aa 100644 --- a/skimage/exposure/exposure.py +++ b/skimage/exposure/exposure.py @@ -14,6 +14,7 @@ __all__ = ['histogram', 'cumulative_distribution', 'equalize', def histogram(image, nbins=256): """Return histogram of image. + Unlike `numpy.histogram`, this function returns the centers of bins and does not rebin integer arrays. For integer arrays, each integer value has its own bin, which improves speed and intensity-resolution. @@ -32,6 +33,14 @@ def histogram(image, nbins=256): The values of the histogram. bin_centers : array The values at the center of the bins. + + Examples + -------- + >>> from skimage import data + >>> hist = histogram(data.camera()) + >>> import matplotlib.pyplot as plt + >>> plt.plot(hist[1], hist[0]) # doctest: +ELLIPSIS + [...] """ # For integer types, histogramming with bincount is more efficient. diff --git a/skimage/filter/ctmf.py b/skimage/filter/ctmf.py index 94f273e1..267c5b6c 100644 --- a/skimage/filter/ctmf.py +++ b/skimage/filter/ctmf.py @@ -42,6 +42,13 @@ def median_filter(image, radius=2, mask=None, percent=50): not overlap the mask, the filtered result is underfined, but in practice, it will be the lowest value in the valid area. + Examples + -------- + >>> a = np.ones((5, 5)) + >>> a[2, 2] = 10 # introduce outlier + >>> b = median_filter(a) + >>> b[2, 2] # the median filter is good at removing outliers + 1.0 ''' if image.ndim != 2: diff --git a/skimage/measure/find_contours.py b/skimage/measure/find_contours.py index 3a546ccf..68e471ac 100755 --- a/skimage/measure/find_contours.py +++ b/skimage/measure/find_contours.py @@ -95,6 +95,17 @@ def find_contours(array, level, Resolution 3D Surface Construction Algorithm. Computer Graphics (SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170). + Examples + -------- + >>> a = np.zeros((3, 3)) + >>> a[0, 0] = 1 + >>> a + array([[ 1., 0., 0.], + [ 0., 0., 0.], + [ 0., 0., 0.]]) + >>> find_contours(a, 0.5) + [array([[ 0. , 0.5], + [ 0.5, 0. ]])] """ array = np.asarray(array, dtype=np.double) if array.ndim != 2: diff --git a/skimage/morphology/greyreconstruct.py b/skimage/morphology/greyreconstruct.py index 09d3c9e6..049488f8 100644 --- a/skimage/morphology/greyreconstruct.py +++ b/skimage/morphology/greyreconstruct.py @@ -60,13 +60,15 @@ def reconstruction(seed, mask, method='dilation', selem=None, offset=None): >>> import numpy as np >>> from skimage.morphology import reconstruction - First, we create a sinusoidal mask image w/ peaks at middle and ends. + First, we create a sinusoidal mask image with peaks at middle and ends. + >>> x = np.linspace(0, 4 * np.pi) >>> y_mask = np.cos(x) Then, we create a seed image initialized to the minimum mask value (for reconstruction by dilation, min-intensity values don't spread) and add "seeds" to the left and right peak, but at a fraction of peak value (1). + >>> y_seed = y_mask.min() * np.ones_like(x) >>> y_seed[0] = 0.5 >>> y_seed[-1] = 0