这是一个很容易解决的问题,我试图在一个平面上重新排列形状,但首先我需要以正确的方式检测它们,我提出了一个非常低效的算法,但它可以很好地完成工作,直到它达到两个形状,这两个形状之间的距离是<;1px:
这里有python伪代码:#all pixels
for x in range(0, image.width):
for y in range(0, image.height):
if pixel is black:
# mark start of shapes
else:
if shape is open:
for r in range (0, image.height):
if pixel is black:
# found shape, keep shape open
else:
# close shape
else:
for r in range (0, image.height):
paint pixel gray # this draws the vertical gray lines in the example
这是生成的图像:
如你所见,灰色条被画在两个形状之间,但当两个形状太近(彼此之间的距离小于1倍)时,它就不起作用了
重要提示:对于垂直重叠的形状,我不需要进行此操作。在
如果你能很好地解释你的算法是什么,它是如何工作的,它看起来像python/PIL代码,那么我就不关心python/pill语法了。在