Rename equalize_hist to equalize and minor cleanup

This commit is contained in:
Tony S Yu
2011-12-22 10:48:28 -08:00
parent 87c2353845
commit d4ca519ca5
4 changed files with 20 additions and 20 deletions
+10 -11
View File
@@ -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)