mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-01 07:27:48 +08:00
Merge pull request #482 from thouis/master
fix rank filters for float structuring element
This commit is contained in:
@@ -101,16 +101,16 @@ cdef void _core16(dtype_t kernel(Py_ssize_t *, float, dtype_t,
|
||||
# build attack and release borders
|
||||
# by using difference along axis
|
||||
t = np.hstack((selem, np.zeros((selem.shape[0], 1))))
|
||||
t_e = np.diff(t, axis=1) == -1
|
||||
t_e = np.diff(t, axis=1) < 0
|
||||
|
||||
t = np.hstack((np.zeros((selem.shape[0], 1)), selem))
|
||||
t_w = np.diff(t, axis=1) == 1
|
||||
t_w = np.diff(t, axis=1) > 0
|
||||
|
||||
t = np.vstack((selem, np.zeros((1, selem.shape[1]))))
|
||||
t_s = np.diff(t, axis=0) == -1
|
||||
t_s = np.diff(t, axis=0) < 0
|
||||
|
||||
t = np.vstack((np.zeros((1, selem.shape[1])), selem))
|
||||
t_n = np.diff(t, axis=0) == 1
|
||||
t_n = np.diff(t, axis=0) > 0
|
||||
|
||||
num_se_n = num_se_s = num_se_e = num_se_w = 0
|
||||
|
||||
|
||||
@@ -104,16 +104,16 @@ cdef void _core8(dtype_t kernel(Py_ssize_t *, float, dtype_t, float,
|
||||
# build attack and release borders
|
||||
# by using difference along axis
|
||||
t = np.hstack((selem, np.zeros((selem.shape[0], 1))))
|
||||
t_e = np.diff(t, axis=1) == -1
|
||||
t_e = np.diff(t, axis=1) < 0
|
||||
|
||||
t = np.hstack((np.zeros((selem.shape[0], 1)), selem))
|
||||
t_w = np.diff(t, axis=1) == 1
|
||||
t_w = np.diff(t, axis=1) > 0
|
||||
|
||||
t = np.vstack((selem, np.zeros((1, selem.shape[1]))))
|
||||
t_s = np.diff(t, axis=0) == -1
|
||||
t_s = np.diff(t, axis=0) < 0
|
||||
|
||||
t = np.vstack((np.zeros((1, selem.shape[1])), selem))
|
||||
t_n = np.diff(t, axis=0) == 1
|
||||
t_n = np.diff(t, axis=0) > 0
|
||||
|
||||
num_se_n = num_se_s = num_se_e = num_se_w = 0
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ __all__ = ['bilateral_mean', 'bilateral_pop']
|
||||
|
||||
|
||||
def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, s0, s1):
|
||||
selem = img_as_ubyte(selem)
|
||||
selem = img_as_ubyte(selem > 0)
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
if mask is None:
|
||||
|
||||
@@ -35,7 +35,7 @@ __all__ = ['percentile_autolevel', 'percentile_gradient',
|
||||
|
||||
|
||||
def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, p0, p1):
|
||||
selem = img_as_ubyte(selem)
|
||||
selem = img_as_ubyte(selem > 0)
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
if mask is None:
|
||||
|
||||
@@ -28,7 +28,7 @@ __all__ = ['autolevel', 'bottomhat', 'equalize', 'gradient', 'maximum', 'mean',
|
||||
|
||||
|
||||
def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y):
|
||||
selem = img_as_ubyte(selem)
|
||||
selem = img_as_ubyte(selem > 0)
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
if mask is None:
|
||||
|
||||
@@ -376,5 +376,25 @@ def test_entropy():
|
||||
assert(np.max(rank.entropy(data, selem)) == 12000)
|
||||
|
||||
|
||||
def test_selem_dtypes():
|
||||
|
||||
image = np.zeros((5, 5), dtype=np.uint8)
|
||||
out = np.zeros_like(image)
|
||||
mask = np.ones_like(image, dtype=np.uint8)
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
for dtype in (np.uint8, np.uint16, np.int32, np.int64,
|
||||
np.float32, np.float64):
|
||||
elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=dtype)
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.percentile_mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user