rr, cc =draw.line(1, 5, 8, 2)
表示从 (1, 5)
到 (8, 2)
连一条线,返回线上所有的像素点坐标 [rr,cc]
。
from skimage import draw,data
from skimage import io
from copy import deepcopy
import matplotlib.pyplot as plt
# img=data.chelsea()
img0=io.imread('/data/demo/img_mxb.jpeg')
img = deepcopy(img0)
rr, cc =draw.line(1, 150, 250, 300)
img[rr, cc] =250
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc84f8f0>
如果想画其它颜色的线条,则可以使用 set_color()
函数,格式为:
skimage.draw.set_color(img, coords, color)
例:
draw.set_color(img,[rr,cc],[255,0,0])
绘制红色线条:
# import matplotlib.pyplot as plt
# img=data.chelsea()
img = deepcopy(img0)
rr, cc =draw.line(1, 150, 270, 250)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc6012e0>
# import matplotlib.pyplot as plt
import numpy as np
# img=data.chelsea()
img = deepcopy(img0)
Y=np.array([10,10,60,60])
X=np.array([200,400,400,200])
rr, cc=draw.polygon(Y,X)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc66d550>
# import matplotlib.pyplot as plt
# img=data.chelsea()
img = deepcopy(img0)
rr, cc=draw.ellipse(150, 150, 30, 80)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbd140d3710>
# import matplotlib.pyplot as plt
# img=data.chelsea()
img = deepcopy(img0)
rr, cc=draw.bezier_curve(150,50,50,280,260,400,2)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc5927b0>
# import matplotlib.pyplot as plt
# img=data.chelsea()
img = deepcopy(img0)
rr, cc=draw.circle_perimeter(150,150,50)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc603440>
# import matplotlib.pyplot as plt
# img=data.chelsea()
img = deepcopy(img0)
rr, cc=draw.ellipse_perimeter(150, 150, 30, 80)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc5d94c0>
# import matplotlib.pyplot as plt
# img=data.chelsea()
# rr, cc=draw.circle(150,150,50)
img = deepcopy(img0)
rr, cc = draw.ellipse(150, 150, 50,50)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fbcbc4828a0>