From d4ca519ca5d95a000b03c10e9ef11dabfd831388 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 22 Dec 2011 10:48:28 -0800 Subject: [PATCH] Rename equalize_hist to equalize and minor cleanup --- doc/examples/plot_equalize_hist.py | 21 ++++++++++----------- skimage/exposure/__init__.py | 2 +- skimage/exposure/exposure.py | 9 +++++---- skimage/exposure/tests/test_exposure.py | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/doc/examples/plot_equalize_hist.py b/doc/examples/plot_equalize_hist.py index 59b8defc..e2ff895e 100644 --- a/doc/examples/plot_equalize_hist.py +++ b/doc/examples/plot_equalize_hist.py @@ -5,7 +5,7 @@ Histogram Equalization This examples takes an image with low contrast and enhances its contrast using histogram equalization. Histogram equalization enhances contrast by "spreading -out the most frequent intensity values" in an image [1]. The equalized image +out the most frequent intensity values" in an image [1]_. The equalized image has a roughly linear cumulative distribution function, as shown in this example. .. [1] http://en.wikipedia.org/wiki/Histogram_equalization @@ -18,25 +18,24 @@ from skimage.util.dtype import dtype_range from skimage import exposure -def plot_hist(img, bins=256, ax=None): +def plot_hist(img, bins=256): """Plot histogram and cumulative histogram for image""" - ax = ax if ax is not None else plt.gca() img_cdf, bins = exposure.cumulative_distribution(img, bins) - ax.hist(img.ravel(), bins=bins) - ax_right = ax.twinx() - ax_right.plot(bins, img_cdf, 'r') + plt.hist(img.ravel(), bins=bins) + ax_cdf = plt.twinx() + ax_cdf.plot(bins, img_cdf, 'r') xmin, xmax = dtype_range[img.dtype.type] - ax.set_xlim(xmin, xmax) + plt.xlim(xmin, xmax) - ax.set_ylabel('# pixels') - ax.set_xlabel('pixel intensiy') - ax_right.set_ylabel('fraction of total intensity') + plt.ylabel('# pixels') + plt.xlabel('pixel intensiy') + ax_cdf.set_ylabel('fraction of total intensity') img_orig = data.camera() # squeeze image intensities to lower image contrast img = img_orig / 5 + 100 -img_eq = exposure.equalize_hist(img) +img_eq = exposure.equalize(img) plt.subplot(2, 2, 1) plt.imshow(img, cmap=plt.cm.gray, vmin=0, vmax=255) diff --git a/skimage/exposure/__init__.py b/skimage/exposure/__init__.py index 1c64aad4..ee5969ab 100644 --- a/skimage/exposure/__init__.py +++ b/skimage/exposure/__init__.py @@ -1 +1 @@ -from exposure import histogram, equalize_hist, cumulative_distribution +from exposure import histogram, equalize, cumulative_distribution diff --git a/skimage/exposure/exposure.py b/skimage/exposure/exposure.py index 06172597..ca16c975 100644 --- a/skimage/exposure/exposure.py +++ b/skimage/exposure/exposure.py @@ -3,14 +3,15 @@ import numpy as np import skimage -__all__ = ['histogram', 'cumulative_distribution', 'equalize_hist'] +__all__ = ['histogram', 'cumulative_distribution', 'equalize'] def histogram(image, nbins, density=True): """Return histogram of image. Unlike `numpy.histogram`, this function returns the centers of bins and - does not rebin integer arrays. + does not rebin integer arrays. For integer arrays, each integer value has + its own bin, which improves speed and intensity-resolution. Parameters ---------- @@ -80,7 +81,7 @@ def cumulative_distribution(image, nbins=256): return img_cdf, bin_centers -def equalize_hist(image, nbins=256): +def equalize(image, nbins=256): """Return image after histogram equalization. Parameters @@ -97,7 +98,7 @@ def equalize_hist(image, nbins=256): Notes ----- - This function is adapted from [1] with the author's permission. + This function is adapted from [1]_ with the author's permission. References ---------- diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index b2d19b8a..22339de7 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -9,16 +9,16 @@ from skimage import exposure test_img = data.camera() / 5 + 100 -def test_equalize_hist_ubyte(): - img_eq = exposure.equalize_hist(test_img) +def test_equalize_ubyte(): + img_eq = exposure.equalize(test_img) cdf, bin_edges = exposure.cumulative_distribution(img_eq) check_cdf_slope(cdf) -def test_equalize_hist_float(): +def test_equalize_float(): img = skimage.img_as_float(test_img) - img_eq = exposure.equalize_hist(img) + img_eq = exposure.equalize(img) cdf, bin_edges = exposure.cumulative_distribution(img_eq) check_cdf_slope(cdf)