Merge pull request #1291 from jni/exposure-fix

Set float histograms bins between 0 and 1
This commit is contained in:
Johannes Schönberger
2014-12-15 09:27:11 +01:00
2 changed files with 15 additions and 6 deletions
+5 -4
View File
@@ -84,7 +84,7 @@ def histogram(image, nbins=256):
idx = np.nonzero(hist)[0][0]
return hist[idx:], bin_centers[idx:]
else:
hist, bin_edges = np.histogram(image.flat, nbins)
hist, bin_edges = np.histogram(image.flat, bins=nbins)
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.
return hist, bin_centers
@@ -136,8 +136,10 @@ def equalize_hist(image, nbins=256, mask=None):
----------
image : array
Image array.
nbins : int
Number of bins for image histogram.
nbins : int, optional
Number of bins for image histogram. Note: this argument is
ignored for integer images, for which each integer is its own
bin.
mask: ndarray of bools or 0s and 1s, optional
Array of same shape as `image`. Only points at which mask == True
are used for the equalization, which is applied to the whole image.
@@ -157,7 +159,6 @@ def equalize_hist(image, nbins=256, mask=None):
.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
"""
image = img_as_float(image)
if mask is not None:
mask = np.array(mask, dtype=bool)
cdf, bin_centers = cumulative_distribution(image[mask], nbins)
+10 -2
View File
@@ -2,7 +2,8 @@ import warnings
import numpy as np
from numpy.testing import assert_array_almost_equal as assert_close
from numpy.testing import assert_array_equal, assert_raises
from numpy.testing import (assert_array_equal, assert_raises,
assert_almost_equal)
import skimage
from skimage import data
@@ -38,10 +39,17 @@ def test_all_negative_image():
np.random.seed(0)
test_img_int = data.camera()
# squeeze image intensities to lower image contrast
test_img = skimage.img_as_float(data.camera())
test_img = skimage.img_as_float(test_img_int)
test_img = exposure.rescale_intensity(test_img / 5. + 100)
def test_equalize_uint8_approx():
"""Check integer bins used for uint8 images."""
img_eq0 = exposure.equalize_hist(test_img_int)
img_eq1 = exposure.equalize_hist(test_img_int, nbins=3)
np.testing.assert_allclose(img_eq0, img_eq1)
def test_equalize_ubyte():
img = skimage.img_as_ubyte(test_img)