1

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.

user3005284
  • 33
  • 2
  • 4

2 Answers2

3

Splines are the standard way to produce smooth curves connecting a set of points. See the Wikipedia.

In Python, you could use scipy.interpolate to compute a smoth curve: scipy.interplote

NPE
  • 486,780
  • 108
  • 951
  • 1,012
3

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.

Timbus Calin
  • 13,809
  • 5
  • 41
  • 59
dragon2fly
  • 2,309
  • 19
  • 23