mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-14 11:18:06 +08:00
Rename equalize_hist to equalize and minor cleanup
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1 +1 @@
|
||||
from exposure import histogram, equalize_hist, cumulative_distribution
|
||||
from exposure import histogram, equalize, cumulative_distribution
|
||||
|
||||
@@ -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
|
||||
----------
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user