将圆盘/圆拉伸成正方形,将正方形挤压成圆盘/圆

squircle的Python项目详细描述


^{}是用于 将圆拉伸成正方形,将正方形挤压成圆形。它需要 Python3.6或更高版本。

安装

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

默认情况下,使用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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java数据未插入SQLite数据库   Java中内存有效的对象创建   java在方法内部使用“this”(不用于调用方法、构造函数或变量)   java为什么这里会出现NullPointerException?   在REST中使用HATEOAS导致的java循环依赖   java如何定制spring boot横幅?   Java数字基数计算器(即基数10到基数5)   如果在Kotlin vs Java中声明,用作全局上下文的安卓 MainApplication类将崩溃   用于过滤对象的Java lambda函数   java从字符串数组中获取整数列表   java为什么Maven找不到org。json JPMS自动模块?   java将字符串数组转换为int   仅当与阈值字节匹配时,java才会在映射中填充字符串值