triangulate.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:LowPoly 作者: Shlw 项目源码 文件源码
def TriAndPaint(img, points, outputIMG):
    tri = Delaunay(points)
    triList = points[tri.simplices]
    cMap = ListedColormap(
        np.array([ChooseColor(img, tr) for tr in triList]))
    # use core rgb
    # center = np.sum(points[tri.simplices], axis=1) / 3
    # print(center)
    # cMap = ListedColormap(
    #     np.array([img.getpixel((x, y)) for x, y in center]) / 256)
    color = np.array(range(len(triList)))
    # print(color)

    width, height = img.size
    plt.figure(figsize=(width, height), dpi=1)
    plt.tripcolor(points[:, 0], points[:, 1],
                  tri.simplices.copy(), facecolors=color, cmap=cMap)
    # plt.tick_params(labelbottom='off', labelleft='off',
    #                 left='off', right='off', bottom='off', top='off')
    # plt.tight_layout(pad=0)
    plt.axis('off')
    plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
    plt.xlim(0, width)
    plt.ylim(0, height)
    plt.gca().invert_yaxis()
    plt.savefig(outputIMG)
    # uncomment show() if you want to view when it's done
    # plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号