我有一个photograph of a retina存储为一个numpy数组。我将用此2D numpy数组表示此图像(我的实际数组更大,具有3个颜色 channel ,值是浮点值,而不是全部0
或1
):
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]])
如何投影圆(以某种方式拉伸(stretch)边缘?),使其变成正方形而不会被裁剪?这样看起来像这样:
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]])
基本上,我正在寻找可以在此图像中进行保形映射的Python库
最佳答案
为此使用 squircle
(免责声明:我写的)
import squircle
import PIL
import numpy as np
square = np.asarray(Image.open('some-square-image.jpg')) # or create the array some other way
circle = squircle.to_circle(square, method="fgs")
and_back_to_square = squircle.to_square(circle, method="fgs")
有3种不同的圆形/正方形变换方法:
"fgs"
,"stretch"
和"elliptical"
它不处理椭圆和矩形,但是您可以通过对图像进行升采样,将其天真地压成一个正方形,在其上运行脉动并将其变回一个矩形来做到这一点。
您可以使用安装
pip install squircle
关于python - 将圆投影到正方形上?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30840833/