将圆盘/圆拉伸成正方形,将正方形挤压成圆盘/圆
squircle的Python项目详细描述
^{
安装
pip insall squircle
用法:
fromsquircleimportto_circle,to_squarefromPILimportImagesquare=np.asarray(Image.open('some-square-image.jpg'))circle=to_circle(square)and_back_to_square=to_square(circle)
有3种拉伸方法可供选择
>>>fromsquircleimportmethods>>>list(methods.keys())['fgs','stretch','elliptical']>>>circle=to_circle(square,method='elliptical')
拉伸方法
费尔南德斯瓜斯蒂斜井(fgs
)
fgs
)默认情况下,使用Fernández Guasti Squircle。
https://squircular.blogspot.com/2015/09/fernandez-guastis-squircle.html
http://mathworld.wolfram.com/Squircle.html
简单拉伸(stretch
)
这种方法只是线性地径向拉伸每个点,使圆的边缘与正方形的边缘相匹配。
https://squircular.blogspot.com/2015/09/elliptical-arc-mapping.html
椭圆网格映射(elliptical
)
“我做这件事的方式是想到一条常数x的线(以及一条常数y的线)被映射到圆的椭圆上”
https://mathproofs.blogspot.com/2005/07/mapping-square-to-circle.html
https://squircular.blogspot.com/2015/09/mapping-circle-to-square.html
schwarz-christoffel共形映射
raise NotImplementedError
。数学很难。
https://squircular.blogspot.com/2015/09/schwarz-christoffel-mapping.html
http://jcgt.org/published/0005/02/01/
这个代码是从Chamberlain Fong的博客帖子上的C++源转换而来的,(我想)是基于他的论文Analytical Methods for Squaring the Disc by C Fong 2014。
Squircle不处理椭圆/矩形,这篇最近的论文应该很有用:Elliptification of Rectangular Imagery by C Fong - 2017
发展
在pip install tox
之后,您可以使用
tox
在ubuntu上,numpy和matplotlib还需要以下依赖项
sudo apt install python3-dev libjpeg-dev zlib1g-dev libfreetype6-dev