From 48328cda8afb954f647355d616d00813efc0006c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Scho=CC=88nberger?= Date: Mon, 23 Apr 2012 17:07:36 +0200 Subject: [PATCH] combined all draw functions in one example script --- doc/examples/plot_polygon.py | 39 ----------------------------- doc/examples/plot_shapes.py | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 39 deletions(-) delete mode 100644 doc/examples/plot_polygon.py create mode 100644 doc/examples/plot_shapes.py diff --git a/doc/examples/plot_polygon.py b/doc/examples/plot_polygon.py deleted file mode 100644 index 6fa58906..00000000 --- a/doc/examples/plot_polygon.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -============ -Fill polygon -============ - -This example shows how to fill polygons in images. -""" - -import matplotlib.pyplot as plt - -from skimage.draw import polygon -import numpy as np - - -img = np.zeros((500, 500), 'uint8') -polygon1 = np.array(( - (50, 50), - (150, 30), - (400, 100), - (300, 200), - (480, 400), - (100, 420), - (50, 50), -)) -polygon2 = np.array(( - (300, 300), - (480, 320), - (380, 430), - (220, 590), - (300, 300), -)) -rr, cc = polygon(polygon1, img.shape) -img[rr,cc] = 127 -rr, cc = polygon(polygon2, img.shape) -img[rr,cc] = 255 - -plt.gray() -plt.imshow(img) -plt.show() \ No newline at end of file diff --git a/doc/examples/plot_shapes.py b/doc/examples/plot_shapes.py new file mode 100644 index 00000000..806049ad --- /dev/null +++ b/doc/examples/plot_shapes.py @@ -0,0 +1,48 @@ +""" +=========== +Fill shapes +=========== + +This example shows how to fill several different shapes: +* line +* polygon +* circle +* ellipse + +""" + +import matplotlib.pyplot as plt + +from skimage.draw import line, polygon, circle, ellipse +import numpy as np + + +img = np.zeros((500, 500, 3), 'uint8') + +#: draw line +rr, cc = line(120, 123, 20, 400) +img[rr,cc,0] = 255 + +#: fill polygon +poly = np.array(( + (300, 300), + (480, 320), + (380, 430), + (220, 590), + (300, 300), +)) +rr, cc = polygon(poly, img.shape) +img[rr,cc,1] = 255 + +#: fill circle +rr, cc = circle(200, 200, 100, img.shape) +img[rr,cc,0] = 255 +rr, cc = circle(200, 200, 100, img.shape) +img[rr,cc,1] = 255 + +#: fill ellipse +rr, cc = ellipse(300, 300, 100, 200, img.shape) +img[rr,cc,2] = 255 + +plt.imshow(img) +plt.show() \ No newline at end of file