mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-12 12:50:49 +08:00
added draw.polygon function with test cases
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from numpy.testing import assert_array_equal
|
||||
import numpy as np
|
||||
|
||||
from skimage.draw import bresenham
|
||||
from skimage.draw import bresenham, polygon
|
||||
|
||||
|
||||
def test_bresenham_horizontal():
|
||||
img = np.zeros((10, 10))
|
||||
@@ -25,7 +26,7 @@ def test_bresenham_vertical():
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
def test_reverse():
|
||||
def test_bresenham_reverse():
|
||||
img = np.zeros((10, 10))
|
||||
|
||||
rr, cc = bresenham(0, 9, 0, 0)
|
||||
@@ -36,7 +37,7 @@ def test_reverse():
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
def test_diag():
|
||||
def test_bresenham_diag():
|
||||
img = np.zeros((5, 5))
|
||||
|
||||
rr, cc = bresenham(0, 0, 4, 4)
|
||||
@@ -47,6 +48,75 @@ def test_diag():
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
|
||||
def test_polygon_rectangle():
|
||||
img = np.zeros((10, 10), 'uint8')
|
||||
poly = np.array(((1, 1), (4, 1), (4, 4), (1, 4), (1, 1)))
|
||||
|
||||
rr, cc = polygon(poly)
|
||||
img[rr,cc] = 1
|
||||
|
||||
img_ = np.zeros((10, 10))
|
||||
img_[1:4,1:4] = 1
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
def test_polygon_rectangle_angular():
|
||||
img = np.zeros((10, 10), 'uint8')
|
||||
poly = np.array(((0, 3), (4, 7), (7, 4), (3, 0), (0, 3)))
|
||||
|
||||
rr, cc = polygon(poly)
|
||||
img[rr,cc] = 1
|
||||
|
||||
img_ = np.array(
|
||||
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
||||
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
||||
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
|
||||
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
|
||||
)
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
def test_polygon_parallelogram():
|
||||
img = np.zeros((10, 10), 'uint8')
|
||||
poly = np.array(((1, 1), (5, 1), (7, 6), (3, 6), (1, 1)))
|
||||
|
||||
rr, cc = polygon(poly)
|
||||
img[rr,cc] = 1
|
||||
|
||||
img_ = np.array(
|
||||
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
|
||||
)
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
def test_polygon_exceed():
|
||||
img = np.zeros((10, 10), 'uint8')
|
||||
poly = np.array(((1, -1), (100, -1), (100, 100), (1, 100), (1, 1)))
|
||||
|
||||
rr, cc = polygon(poly, img.shape)
|
||||
img[rr,cc] = 1
|
||||
|
||||
img_ = np.zeros((10, 10))
|
||||
img_[1:,:] = 1
|
||||
|
||||
assert_array_equal(img, img_)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from numpy.testing import run_module_suite
|
||||
|
||||
run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user