mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
fix:wrap lines in tests
This commit is contained in:
@@ -17,26 +17,26 @@ def test_random_sizes():
|
||||
image8 = np.ones((m, n), dtype=np.uint8)
|
||||
out8 = np.empty_like(image8)
|
||||
rank.mean(image=image8, selem=elem, mask=mask, out=out8,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image8.shape, out8.shape)
|
||||
rank.mean(image=image8, selem=elem, mask=mask, out=out8,
|
||||
shift_x=+1, shift_y=+1)
|
||||
shift_x=+1, shift_y=+1)
|
||||
assert_array_equal(image8.shape, out8.shape)
|
||||
|
||||
image16 = np.ones((m, n), dtype=np.uint16)
|
||||
out16 = np.empty_like(image8, dtype=np.uint16)
|
||||
rank.mean(image=image16, selem=elem, mask=mask, out=out16,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image16.shape, out16.shape)
|
||||
rank.mean(image=image16, selem=elem, mask=mask, out=out16,
|
||||
shift_x=+1, shift_y=+1)
|
||||
shift_x=+1, shift_y=+1)
|
||||
assert_array_equal(image16.shape, out16.shape)
|
||||
|
||||
rank.percentile_mean(image=image16, mask=mask, out=out16,
|
||||
selem=elem, shift_x=0, shift_y=0, p0=.1, p1=.9)
|
||||
selem=elem, shift_x=0, shift_y=0, p0=.1, p1=.9)
|
||||
assert_array_equal(image16.shape, out16.shape)
|
||||
rank.percentile_mean(image=image16, mask=mask, out=out16,
|
||||
selem=elem, shift_x=+1, shift_y=+1, p0=.1, p1=.9)
|
||||
selem=elem, shift_x=+1, shift_y=+1, p0=.1, p1=.9)
|
||||
assert_array_equal(image16.shape, out16.shape)
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ def test_bitdepth():
|
||||
mask = np.ones((100, 100), dtype=np.uint8)
|
||||
|
||||
for i in range(5):
|
||||
image = np.ones((100, 100),dtype=np.uint16) * 255 * 2**i
|
||||
image = np.ones((100, 100), dtype=np.uint16) * 255 * 2 ** i
|
||||
r = rank.percentile_mean(image=image, selem=elem, mask=mask,
|
||||
out=out, shift_x=0, shift_y=0, p0=.1, p1=.9)
|
||||
out=out, shift_x=0, shift_y=0, p0=.1, p1=.9)
|
||||
|
||||
|
||||
def test_population():
|
||||
@@ -101,12 +101,12 @@ def test_population():
|
||||
def test_structuring_element8():
|
||||
# check the output for a custom structuring element
|
||||
|
||||
r = np.array([[ 0, 0, 0, 0, 0, 0],
|
||||
[ 0, 0, 0, 0, 0, 0],
|
||||
[ 0, 0, 255, 0, 0, 0],
|
||||
[ 0, 0, 255, 255, 255, 0],
|
||||
[ 0, 0, 0, 255, 255, 0],
|
||||
[ 0, 0, 0, 0, 0, 0]])
|
||||
r = np.array([[0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 255, 0, 0, 0],
|
||||
[0, 0, 255, 255, 255, 0],
|
||||
[0, 0, 0, 255, 255, 0],
|
||||
[0, 0, 0, 0, 0, 0]])
|
||||
|
||||
# 8-bit
|
||||
image = np.zeros((6, 6), dtype=np.uint8)
|
||||
@@ -116,7 +116,7 @@ def test_structuring_element8():
|
||||
mask = np.ones(image.shape, dtype=np.uint8)
|
||||
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=1, shift_y=1)
|
||||
shift_x=1, shift_y=1)
|
||||
assert_array_equal(r, out)
|
||||
|
||||
# 16-bit
|
||||
@@ -125,24 +125,25 @@ def test_structuring_element8():
|
||||
out = np.empty_like(image)
|
||||
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=1, shift_y=1)
|
||||
shift_x=1, shift_y=1)
|
||||
assert_array_equal(r, out)
|
||||
|
||||
|
||||
def test_fail_on_bitdepth():
|
||||
# should fail because data bitdepth is too high for the function
|
||||
|
||||
image = np.ones((100, 100), dtype=np.uint16) * 2**12
|
||||
image = np.ones((100, 100), dtype=np.uint16) * 2 ** 12
|
||||
elem = np.ones((3, 3), dtype=np.uint8)
|
||||
out = np.empty_like(image)
|
||||
mask = np.ones(image.shape, dtype=np.uint8)
|
||||
assert_raises(ValueError, rank.percentile_mean, image=image,
|
||||
selem=elem, out=out, mask=mask, shift_x=0, shift_y=0)
|
||||
selem=elem, out=out, mask=mask, shift_x=0, shift_y=0)
|
||||
|
||||
|
||||
def test_pass_on_bitdepth():
|
||||
# should pass because data bitdepth is not too high for the function
|
||||
|
||||
image = np.ones((100, 100), dtype=np.uint16) * 2**11
|
||||
image = np.ones((100, 100), dtype=np.uint16) * 2 ** 11
|
||||
elem = np.ones((3, 3), dtype=np.uint8)
|
||||
out = np.empty_like(image)
|
||||
mask = np.ones(image.shape, dtype=np.uint8)
|
||||
@@ -152,7 +153,7 @@ def test_inplace_output():
|
||||
# rank filters are not supposed to filter inplace
|
||||
|
||||
selem = disk(20)
|
||||
image = (np.random.random((500,500))*256).astype(np.uint8)
|
||||
image = (np.random.random((500, 500)) * 256).astype(np.uint8)
|
||||
out = image
|
||||
assert_raises(NotImplementedError, rank.mean, image, selem, out=out)
|
||||
|
||||
@@ -166,7 +167,7 @@ def test_compare_autolevels():
|
||||
selem = disk(20)
|
||||
loc_autolevel = rank.autolevel(image, selem=selem)
|
||||
loc_perc_autolevel = rank.percentile_autolevel(image, selem=selem,
|
||||
p0=.0, p1=1.)
|
||||
p0=.0, p1=1.)
|
||||
|
||||
assert_array_equal(loc_autolevel, loc_perc_autolevel)
|
||||
|
||||
@@ -180,7 +181,7 @@ def test_compare_autolevels_16bit():
|
||||
selem = disk(20)
|
||||
loc_autolevel = rank.autolevel(image, selem=selem)
|
||||
loc_perc_autolevel = rank.percentile_autolevel(image, selem=selem,
|
||||
p0=.0, p1=1.)
|
||||
p0=.0, p1=1.)
|
||||
|
||||
assert_array_equal(loc_autolevel, loc_perc_autolevel)
|
||||
|
||||
@@ -195,7 +196,7 @@ def test_compare_8bit_vs_16bit():
|
||||
|
||||
methods = ['autolevel', 'bottomhat', 'equalize', 'gradient', 'maximum',
|
||||
'mean', 'meansubstraction', 'median', 'minimum', 'modal',
|
||||
'morph_contr_enh', 'pop', 'threshold', 'tophat']
|
||||
'morph_contr_enh', 'pop', 'threshold', 'tophat']
|
||||
|
||||
for method in methods:
|
||||
func = getattr(rank, method)
|
||||
@@ -211,19 +212,19 @@ def test_trivial_selem8():
|
||||
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
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
elem = np.array([[0, 0, 0], [0, 1, 0],[0, 0, 0]], dtype=np.uint8)
|
||||
elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=np.uint8)
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.minimum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
|
||||
|
||||
@@ -234,19 +235,19 @@ def test_trivial_selem16():
|
||||
image = np.zeros((5, 5), dtype=np.uint16)
|
||||
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
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
elem = np.array([[0, 0, 0], [0, 1, 0],[0, 0, 0]], dtype=np.uint8)
|
||||
elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=np.uint8)
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.minimum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
|
||||
|
||||
@@ -257,19 +258,19 @@ def test_smallest_selem8():
|
||||
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
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
elem = np.array([[1]], dtype=np.uint8)
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.minimum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
|
||||
|
||||
@@ -280,21 +281,22 @@ def test_smallest_selem16():
|
||||
image = np.zeros((5, 5), dtype=np.uint16)
|
||||
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
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
elem = np.array([[1]], dtype=np.uint8)
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.minimum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(image, out)
|
||||
|
||||
|
||||
def test_empty_selem():
|
||||
# check that min, max and mean returns zeros if structuring element is empty
|
||||
|
||||
@@ -302,64 +304,74 @@ def test_empty_selem():
|
||||
out = np.zeros_like(image)
|
||||
mask = np.ones_like(image, dtype=np.uint8)
|
||||
res = np.zeros_like(image)
|
||||
image[2,2] = 255
|
||||
image[2,3] = 128
|
||||
image[1,2] = 16
|
||||
image[2, 2] = 255
|
||||
image[2, 3] = 128
|
||||
image[1, 2] = 16
|
||||
|
||||
elem = np.array([[0,0,0],[0,0,0]], dtype=np.uint8)
|
||||
elem = np.array([[0, 0, 0], [0, 0, 0]], dtype=np.uint8)
|
||||
|
||||
rank.mean(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(res, out)
|
||||
rank.minimum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(res, out)
|
||||
rank.maximum(image=image, selem=elem, out=out, mask=mask,
|
||||
shift_x=0, shift_y=0)
|
||||
shift_x=0, shift_y=0)
|
||||
assert_array_equal(res, out)
|
||||
|
||||
|
||||
def test_otsu():
|
||||
#
|
||||
test = np.tile([128, 145, 103, 127, 165, 83, 127, 185, 63, 127, 205, 43, 127, 225, 23, 127],(16,1))
|
||||
test = np.tile(
|
||||
[128, 145, 103, 127, 165, 83, 127, 185, 63, 127, 205, 43,
|
||||
127, 225, 23, 127],
|
||||
(16, 1))
|
||||
test = test.astype(np.uint8)
|
||||
res = np.tile([1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1],(16,1))
|
||||
selem = np.ones((6,6), dtype=np.uint8)
|
||||
th = 1*(test>=rank.otsu(test,selem))
|
||||
assert_array_equal(th,res)
|
||||
res = np.tile([1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1],
|
||||
(16, 1))
|
||||
selem = np.ones((6, 6), dtype=np.uint8)
|
||||
th = 1 * (test >= rank.otsu(test, selem))
|
||||
assert_array_equal(th, res)
|
||||
|
||||
|
||||
def test_entropy():
|
||||
# verify that entropy is coherent with bitdepth of the input data
|
||||
|
||||
selem = np.ones((16,16), dtype=np.uint8)
|
||||
selem = np.ones((16, 16), dtype=np.uint8)
|
||||
# 1 bit per pixel
|
||||
data = np.tile(np.asarray([0,1]),(100,100)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==10)
|
||||
data = np.tile(np.asarray([0, 1]), (100, 100)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 10)
|
||||
|
||||
# 2 bit per pixel
|
||||
data = np.tile(np.asarray([[0,1],[2,3]]),(10,10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==20)
|
||||
data = np.tile(np.asarray([[0, 1], [2, 3]]), (10, 10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 20)
|
||||
|
||||
# 3 bit per pixel
|
||||
data = np.tile(np.asarray([[0,1,2,3],[4,5,6,7]]),(10,10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==30)
|
||||
data = np.tile(
|
||||
np.asarray([[0, 1, 2, 3], [4, 5, 6, 7]]), (10, 10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 30)
|
||||
|
||||
# 4 bit per pixel
|
||||
data = np.tile(np.reshape(np.arange(16),(4,4)),(10,10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==40)
|
||||
data = np.tile(
|
||||
np.reshape(np.arange(16), (4, 4)), (10, 10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 40)
|
||||
|
||||
# 6 bit per pixel
|
||||
data = np.tile(np.reshape(np.arange(64),(8,8)),(10,10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==60)
|
||||
data = np.tile(
|
||||
np.reshape(np.arange(64), (8, 8)), (10, 10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 60)
|
||||
|
||||
# 8-bit per pixel
|
||||
data = np.tile(np.reshape(np.arange(256),(16,16)),(10,10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data,selem))==80)
|
||||
data = np.tile(
|
||||
np.reshape(np.arange(256), (16, 16)), (10, 10)).astype(np.uint8)
|
||||
assert(np.max(rank.entropy(data, selem)) == 80)
|
||||
|
||||
# 12 bit per pixel
|
||||
selem = np.ones((64,64), dtype=np.uint8)
|
||||
data = np.tile(np.reshape(np.arange(4096),(64,64)),(2,2)).astype(np.uint16)
|
||||
assert(np.max(rank.entropy(data,selem))==12000)
|
||||
selem = np.ones((64, 64), dtype=np.uint8)
|
||||
data = np.tile(
|
||||
np.reshape(np.arange(4096), (64, 64)), (2, 2)).astype(np.uint16)
|
||||
assert(np.max(rank.entropy(data, selem)) == 12000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user