python数字图像处理（12）：基本图形的绘制

48 篇文章 1 订阅

1、画线条

skimage.draw.line(r1,c1,r2,c2)

r1,r2: 开始点的行数和结束点的行数

c1,c2: 开始点的列数和结束点的列数

rr, cc =draw.line(1, 5, 8, 2)

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc =draw.line(1, 150, 470, 450)
img[rr, cc] =255
plt.imshow(img,plt.cm.gray)

skimage.draw.set_color(imgcoordscolor)

draw.set_color(img,[rr,cc],[255,0,0])

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc =draw.line(1, 150, 270, 250)
draw.set_color(img,[rr,cc],[0,0,255])
plt.imshow(img,plt.cm.gray)

2、画圆

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc=draw.circle(150,150,50)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)

3、多边形

Y为多边形顶点的行集合，X为各顶点的列值集合。

from skimage import draw,data
import matplotlib.pyplot as plt
import numpy as np
img=data.chelsea()
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)

4、椭圆

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc=draw.ellipse(150, 150, 30, 80)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)

5、贝塞儿曲线

y1,x1表示第一个控制点坐标

y2,x2表示第二个控制点坐标

y3,x3表示第三个控制点坐标

weight表示中间控制点的权重，用于控制曲线的弯曲度。

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
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)

6、画空心圆

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc=draw.circle_perimeter(150,150,50)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)

7、空心椭圆

cy,cx表示圆心

from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc=draw.ellipse_perimeter(150, 150, 30, 80)
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

01-11 273

08-07 2949
01-11 4695
01-26 662
07-21 1220
12-20