rr, cc =draw.line(1, 5, 8, 2)表示从 (1, 5) 到 (8, 2) 连一条线,返回线上所有的像素点坐标 [rr,cc]。
In [2]:
from skimage import draw,data
from skimage import io
from copy import deepcopy
In [3]:
import matplotlib.pyplot as plt
# img=data.chelsea()
In [4]:
img0=io.imread('/data/demo/img_mxb.jpeg')
In [5]:
img = deepcopy(img0)
In [6]:
rr, cc =draw.line(1, 150, 250, 300)
img[rr, cc] =250
plt.imshow(img,plt.cm.gray)
Out[6]:
<matplotlib.image.AxesImage at 0x7fbcbc84f8f0>
如果想画其它颜色的线条,则可以使用 set_color() 函数,格式为:
skimage.draw.set_color(img, coords, color)例:
draw.set_color(img,[rr,cc],[255,0,0])绘制红色线条:
In [7]:
# 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)
Out[7]:
<matplotlib.image.AxesImage at 0x7fbcbc6012e0>
In [8]:
# import matplotlib.pyplot as plt
import numpy as np
# img=data.chelsea()
In [9]:
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)
Out[9]:
<matplotlib.image.AxesImage at 0x7fbcbc66d550>
In [10]:
# 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)
Out[10]:
<matplotlib.image.AxesImage at 0x7fbd140d3710>
In [11]:
# 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)
Out[11]:
<matplotlib.image.AxesImage at 0x7fbcbc5927b0>
In [12]:
# 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)
Out[12]:
<matplotlib.image.AxesImage at 0x7fbcbc603440>
In [13]:
# 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)
Out[13]:
<matplotlib.image.AxesImage at 0x7fbcbc5d94c0>
In [14]:
# 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)
Out[14]:
<matplotlib.image.AxesImage at 0x7fbcbc4828a0>