mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-09 11:33:41 +08:00
Merge pull request #1291 from jni/exposure-fix
Set float histograms bins between 0 and 1
This commit is contained in:
@@ -84,7 +84,7 @@ def histogram(image, nbins=256):
|
|||||||
idx = np.nonzero(hist)[0][0]
|
idx = np.nonzero(hist)[0][0]
|
||||||
return hist[idx:], bin_centers[idx:]
|
return hist[idx:], bin_centers[idx:]
|
||||||
else:
|
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.
|
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.
|
||||||
return hist, bin_centers
|
return hist, bin_centers
|
||||||
|
|
||||||
@@ -136,8 +136,10 @@ def equalize_hist(image, nbins=256, mask=None):
|
|||||||
----------
|
----------
|
||||||
image : array
|
image : array
|
||||||
Image array.
|
Image array.
|
||||||
nbins : int
|
nbins : int, optional
|
||||||
Number of bins for image histogram.
|
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
|
mask: ndarray of bools or 0s and 1s, optional
|
||||||
Array of same shape as `image`. Only points at which mask == True
|
Array of same shape as `image`. Only points at which mask == True
|
||||||
are used for the equalization, which is applied to the whole image.
|
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
|
.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
|
||||||
|
|
||||||
"""
|
"""
|
||||||
image = img_as_float(image)
|
|
||||||
if mask is not None:
|
if mask is not None:
|
||||||
mask = np.array(mask, dtype=bool)
|
mask = np.array(mask, dtype=bool)
|
||||||
cdf, bin_centers = cumulative_distribution(image[mask], nbins)
|
cdf, bin_centers = cumulative_distribution(image[mask], nbins)
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import warnings
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.testing import assert_array_almost_equal as assert_close
|
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
|
import skimage
|
||||||
from skimage import data
|
from skimage import data
|
||||||
@@ -38,10 +39,17 @@ def test_all_negative_image():
|
|||||||
|
|
||||||
np.random.seed(0)
|
np.random.seed(0)
|
||||||
|
|
||||||
|
test_img_int = data.camera()
|
||||||
# squeeze image intensities to lower image contrast
|
# 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)
|
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():
|
def test_equalize_ubyte():
|
||||||
img = skimage.img_as_ubyte(test_img)
|
img = skimage.img_as_ubyte(test_img)
|
||||||
|
|||||||
Reference in New Issue
Block a user