Python平滑曲线 [英] Python smooth curve

查看:90
本文介绍了Python平滑曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组非常紧密的坐标.我通过使用python的image.draw.line()在它们之间画线来连接这些坐标.但是获得的最终曲线并不平滑,因为坐标处的线没有正确相交.我也尝试绘制圆弧而不是直线,但是image.draw.arc()不会为坐标输入任何浮点输入.谁能建议我其他方法连接这些点,以使最终曲线平滑.

解决方案

枕头不支持多种绘制线条的方法.如果您尝试绘制拱形,则没有选择厚度的选项!

scipy使用matplotlib绘制图形.因此,如果您直接使用matplotlib绘制线,则可以通过 axis('off')命令关闭轴.有关更多详细信息,您可以查看: Matplotlib图:删除轴,图例和空白

如果您与轴没有任何关系,建议您使用OpenCV而不是Pillow来处理图像.

  def draw_line(point_lists):宽,高= 640、480#图片的大小img = np.zeros((height,width,3),np.uint8)+ 255#使背景变白line_width = 1对于point_lists中的行:color =(123,123,123)#更改颜色或为自己创建颜色生成器pts = np.array(line,dtype = np.int32)cv2.polylines(img,[pts],False,color,thickness = line_width,lineType = cv2.LINE_AA)cv2.imshow("Art",img)cv2.waitKey(0)#毫秒,0表示永远等待 

lineType =cv2.LINE_AA会画出一条漂亮的抗锯齿线.

I have set of very closely spaced coordinates. I am connecting those coordinates by drawing line between them by using python's image.draw.line(). But the final curve obtained is not smooth as the lines at the coordinates are not properly intersecting.I also tried drawing arc instead of lines but image.draw.arc() would not take any float input for coordinates. Can anyone suggest me other method to connect those points such that final curve will be smooth.

解决方案

Pillow doesn't support many way to draw a line. If you try to draw an arch, there is no options for you to choose thickness!

scipy use matplotlib to draw graph. So if you draw lines directly with matplotlib, you can turn off the axes by axis('off') command. For more detail, you may have a look at: Matplotlib plots: removing axis, legends and white spaces

If you don't have anything to do with axes, I would recommend you to use OpenCV instead of Pillow to handle images.

def draw_line(point_lists):
    width, height = 640, 480  # picture's size
    img = np.zeros((height, width, 3), np.uint8) + 255 # make the background white
    line_width = 1
    for line in point_lists:
        color = (123,123,123) # change color or make a color generator for your self
        pts = np.array(line, dtype=np.int32)
        cv2.polylines(img, [pts], False, color, thickness=line_width, lineType=cv2.LINE_AA)
    cv2.imshow("Art", img)
    cv2.waitKey(0)    # miliseconds, 0 means wait forever

lineType=cv2.LINE_AA will draw an antialiased line which is beautiful.

这篇关于Python平滑曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆