mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
Add handling for images with negative integers
This commit is contained in:
@@ -16,10 +16,9 @@ class TestSimpleImage():
|
||||
def test_otsu(self):
|
||||
assert threshold_otsu(self.image) == 2
|
||||
|
||||
@np.testing.raises(NotImplementedError)
|
||||
def test_otsu_raises_error(self):
|
||||
def test_otsu_negative_int(self):
|
||||
image = self.image - 2
|
||||
threshold_otsu(image)
|
||||
assert threshold_otsu(image) == 0
|
||||
|
||||
def test_otsu_float_image(self):
|
||||
image = np.float64(self.image)
|
||||
|
||||
@@ -89,11 +89,11 @@ def histogram(image, bins):
|
||||
The values at the center of the bins.
|
||||
"""
|
||||
if np.issubdtype(image.dtype, np.integer):
|
||||
offset = 0
|
||||
if np.min(image) < 0:
|
||||
msg = "Images with negative values not allowed"
|
||||
raise NotImplementedError(msg)
|
||||
hist = np.bincount(image.flat)
|
||||
bin_centers = np.arange(len(hist))
|
||||
offset = np.min(image)
|
||||
hist = np.bincount(image.ravel() - offset)
|
||||
bin_centers = np.arange(len(hist)) + offset
|
||||
|
||||
# clip histogram to return only non-zero bins
|
||||
idx = np.nonzero(hist)[0][0]
|
||||
|
||||
Reference in New Issue
Block a user