mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-14 11:18:06 +08:00
Upadated Version with test added(/filter/tests/test_edge.py
This commit is contained in:
@@ -362,8 +362,10 @@ def roberts(image, mask=None):
|
||||
|
||||
def pdroberts(image, mask=None):
|
||||
"""Find the cross edges of an image using the Roberts' Cross operator.
|
||||
|
||||
The kernel is applied to the input image, to produce separate measurements
|
||||
of the gradient component one orientation.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : 2-D array
|
||||
@@ -376,7 +378,7 @@ def pdroberts(image, mask=None):
|
||||
Returns
|
||||
-------
|
||||
output : ndarray
|
||||
The Robert edge map.
|
||||
The Robert's edge map.
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -390,7 +392,7 @@ def pdroberts(image, mask=None):
|
||||
image = img_as_float(image)
|
||||
result = np.abs(convolve(image,
|
||||
np.array([[ 1, 0],
|
||||
[ 0, -1]]).astype(float) / 1.0 ))
|
||||
[ 0, -1]]).astype(float)))
|
||||
return _mask_filter_result(result, mask)
|
||||
|
||||
|
||||
@@ -410,7 +412,7 @@ def ndroberts(image, mask=None):
|
||||
Returns
|
||||
-------
|
||||
output : ndarray
|
||||
The Robert edge map.
|
||||
The Robert's edge map.
|
||||
|
||||
Notes
|
||||
-----
|
||||
@@ -424,5 +426,5 @@ def ndroberts(image, mask=None):
|
||||
image = img_as_float(image)
|
||||
result = np.abs(convolve(image,
|
||||
np.array([[0, 1],
|
||||
[-1, 0]]).astype(float) / 1.0))
|
||||
[-1, 0]]).astype(float)))
|
||||
return _mask_filter_result(result, mask)
|
||||
|
||||
@@ -4,6 +4,55 @@ from numpy.testing import assert_array_almost_equal as assert_close
|
||||
import skimage.filter as F
|
||||
|
||||
|
||||
def test_roberts_zeros():
|
||||
"""Roberts' on an array of all zeros"""
|
||||
result = F.roberts(np.zeros((10, 10)), np.ones((10, 10), bool))
|
||||
assert (np.all(result == 0))
|
||||
|
||||
|
||||
def test_roberts_diagonal1():
|
||||
"""Roberts' on an edge should be a diagonal"""
|
||||
i = (10, 10)
|
||||
n = (10, 10)
|
||||
i = np.ones(i)
|
||||
i = np.triu(i)
|
||||
image = (i > 0).astype(float)
|
||||
n = np.zeros(n)
|
||||
for k in range(2, 10):
|
||||
for t in range(0, k-1):
|
||||
n[k][t] = 1
|
||||
n[t][k] = 1
|
||||
j = np.identity(10)
|
||||
result = F.roberts(image)
|
||||
j[9][9] = j[0][0] = 0
|
||||
assert (np.all(result[j == 1] == 1) and np.all(result[n == 1] == 0))
|
||||
|
||||
|
||||
def test_roberts_diagonal2():
|
||||
"""Roberts' on an edge should be a diagonal"""
|
||||
i = (10, 10)
|
||||
j = (10, 10)
|
||||
n = (10, 10)
|
||||
i = np.ones(i)
|
||||
for k in range(0, 10):
|
||||
for t in range(10-k, 10):
|
||||
i[k][t] = 0
|
||||
n = np.zeros(n)
|
||||
for k in range(0, 10):
|
||||
for t in range(0, 9-k):
|
||||
n[k][t] = 0
|
||||
n[t][k] = 0
|
||||
|
||||
image = (i > 0).astype(float)
|
||||
|
||||
j = np.ones(j)
|
||||
for k in range(0, 10):
|
||||
j[k][9-k] = 5
|
||||
result = F.roberts(image)
|
||||
j[0][9] = j[9][0] = 0
|
||||
assert (np.all(result[j == 5] == 1) and np.all(result[n == 1] == 0))
|
||||
|
||||
|
||||
def test_sobel_zeros():
|
||||
"""Sobel on an array of all zeros"""
|
||||
result = F.sobel(np.zeros((10, 10)), np.ones((10, 10), bool))
|
||||
|
||||
Reference in New Issue
Block a user