Merge pull request #774 from ahojnnes/shape-plot

Add anti-aliased circle and line to the shapes example.
This commit is contained in:
Juan Nunez-Iglesias
2013-10-11 16:26:59 -07:00
+25 -22
View File
@@ -4,7 +4,6 @@ Shapes
======
This example shows how to draw several different shapes:
* line
* Bezier curve
* polygon
@@ -12,6 +11,7 @@ This example shows how to draw several different shapes:
* ellipse
"""
import math
import numpy as np
import matplotlib.pyplot as plt
@@ -19,9 +19,12 @@ from skimage.draw import (line, polygon, circle,
circle_perimeter,
ellipse, ellipse_perimeter,
bezier_curve)
import math
img = np.zeros((500, 500, 3), dtype=np.uint8)
fig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(10, 6))
img = np.zeros((500, 500, 3), dtype=np.double)
# draw line
rr, cc = line(120, 123, 20, 400)
@@ -36,34 +39,35 @@ poly = np.array((
(300, 300),
))
rr, cc = polygon(poly[:, 0], poly[:, 1], img.shape)
img[rr, cc, 1] = 255
img[rr, cc, 1] = 1
# fill circle
rr, cc = circle(200, 200, 100, img.shape)
img[rr, cc, :] = (255, 255, 0)
img[rr, cc, :] = (1, 1, 0)
# fill ellipse
rr, cc = ellipse(300, 300, 100, 200, img.shape)
img[rr, cc, 2] = 255
img[rr, cc, 2] = 1
# circle
rr, cc = circle_perimeter(120, 400, 15)
img[rr, cc, :] = (255, 0, 0)
img[rr, cc, :] = (1, 0, 0)
# Bezier curve
rr, cc = bezier_curve(70, 100, 10, 10, 150, 100, 1)
img[rr, cc, :] = (255, 0, 0)
img[rr, cc, :] = (1, 0, 0)
# ellipses
rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 4.)
img[rr, cc, :] = (255, 0, 255)
img[rr, cc, :] = (1, 0, 1)
rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=-math.pi / 4.)
img[rr, cc, :] = (0, 0, 255)
img[rr, cc, :] = (0, 0, 1)
rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 2.)
img[rr, cc, :] = (255, 255, 255)
img[rr, cc, :] = (1, 1, 1)
plt.imshow(img)
plt.show()
ax1.imshow(img)
ax1.set_title('No anti-aliasing')
ax1.axis('off')
"""
@@ -73,23 +77,22 @@ Anti-aliased drawing for:
"""
import numpy as np
import matplotlib.pyplot as plt
from skimage.draw import line_aa, circle_perimeter_aa
from skimage.draw import (line_aa,
circle_perimeter_aa)
img = np.zeros((100, 100), dtype=np.uint8)
img = np.zeros((100, 100), dtype=np.double)
# anti-aliased line
rr, cc, val = line_aa(12, 12, 20, 50)
img[rr, cc] = val * 255
img[rr, cc] = val
# anti-aliased circle
rr, cc, val = circle_perimeter_aa(60, 40, 30)
img[rr, cc] = val * 255
img[rr, cc] = val
plt.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
plt.title('Anti-aliasing')
ax2.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
ax2.set_title('Anti-aliasing')
ax2.axis('off')
plt.show()