这是一个读写.tps文件的简单库,由f.james rohlf创建的tpsdig标记工具创建和使用。https://life.bio.sunysb.edu/morphi/
py-tps的Python项目详细描述
这是一个用于读写tpsdig标记工具创建和使用的.tps文件的简单库 由F.JamesRohlf创作。https://life.bio.sunysb.edu/morph/
安装
安装的主要方式是从pip:
pip install py_tps
源代码安装通过诗歌进行管理。https://pypi.org/project/poetry/ 来源可以从https://gitlab.com/ryan-feather/py_tps
要安装,首先安装诗歌。
conda用户的注释
要将conda环境与poetry一起使用,必须首先将poetry配置为使用conda环境和 不创建新的virtualenv环境。示例:
poetry config settings.virtualenvs.path $CONDA_ENV_PATH poetry config settings.virtualenvs.create 0
然后运行:
poetry install poetry build cd dist pip install *.whl
用法
from py_tps import TPSFile, TPSImage, TPSCurve, TPSPoints import numpy as np # construct and write # numpy is used for numeric data points = TPSPoints(np.asarray([[33,44], [44,45]])) curve = TPSCurve(points) image = TPSImage('T1.JPG', curves=[curve], id_number=0, comment="This is a test", scale=0.0045) tps_file = TPSFile([image]) # can have many images, but here we do just one tps_file.write_to_file('TestFile.TPS')
创建包含以下内容的文件:
LM=0 CURVES=1 POINTS=2 33 44 44 45 IMAGE=T1.JPG ID=0 COMMENT=This is a test SCALE=0.0045
现在阅读:
tps_file_in =TPSFile.read_file('TestFile.TPS') # now can access images list, and so on. Attributes have the same names as they do in the objects above. print(tps_file.images[0].image) # T1.JPG print(tps_file.images[0].curves[0].tps_points.points) # [[33,44],[44,45]]
地标可以设置,而不是曲线。如果我们这样做:
image = TPSImage('T1.JPG', landmarks=points, id_number=0, comment="This is a test", scale=0.0045)
它创建包含以下内容的文件:
LM=2 33 44 44 45 IMAGE=T1.JPG ID=0 COMMENT=This is a test SCALE=0.0045