【问题标题】:Non-affine transformation with PIL使用 PIL 进行非仿射变换
【发布时间】:2013-10-02 16:58:31
【问题描述】:

我有一个矩形图像 (O),我想将它环绕成一个圆圈 (I)。基本上我想取两个笛卡尔坐标轴xy并将它们映射到极坐标φr,这样I(φ,r) = O(f(φ),g(r))就是fg线性函数。

我在 PIL 中找到了 Image.transform 方法,但是当我阅读 the documentation 时,这仅适用于仿射变换矩阵。

1.这种“将矩形包裹成圆形”可以通过仿射变换完成吗?我担心不会。

2。我还能如何做到这一点?

【问题讨论】:

  • 你将不得不编写自己的图像处理代码——可能不是在 Python 中使用或不使用 PIL——或者使用其他一些可以做你想做的事情的预先编写的模块。跨度>

标签: python python-imaging-library transformation


【解决方案1】:

根据 martineau 的说法,PIL 中没有这样的功能,我必须自己实现它:

成为overlay 笛卡尔图像和circle 极坐标图像。

for x in range (800):
    for y in range (800):
        r = ( (x - 400) ** 2 + (y - 400) ** 2) ** .5
        phi = math.atan2 (float (y - 400), float (x - 400) )
        tx = int (phi * 1200.0 / 2.0 / math.pi + 300) % 1200
        ty = int ( (r - 100.0) * 350.0 / 250.0)
        if 100 < r < 350: circle.putpixel ( (x, y), overlay.getpixel ( (tx, ty) ) )

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 2022-01-24
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    相关资源
    最近更新 更多