三维立体图像中椭球体的绘制与分析。

pyellipsoid的Python项目详细描述


https://travis-ci.org/ashkarin/pyellipsoid.svg?branch=master

py椭球是用于绘制和分析三维体积图像(3d数组)中椭球的软件包。

安装

安装最新版本的最简单方法是使用pip:

$ pip install pyellipsoid

您还可以使用git克隆存储库并手动安装:

$ git clone https://github.com/ashkarin/pyellipsoid.git
$ cd pyellipsoid
$ python setup.py install

如何使用

绘制椭球体:

importnumpyasnpfrompyellipsoidimportdrawing# Define an image shape, axis order is: Z, Y, Ximage_shape=(128,128,128)# Define an ellipsoid, axis order is: X, Y, Zell_center=(64,64,64)ell_radii=(5,50,30)ell_angles=np.deg2rad([80,30,20])# Order of rotations is X, Y, Z# Draw a 3D binary image containing the ellipsoidimage=drawing.make_ellipsoid_image(image_shape,ell_center,ell_radii,ell_angles)

计算给定椭球图像的惯性椭球:

importnumpyasnpfrompyellipsoidimportdrawing,analysis# Draw a 3D binary image containing an ellipsoidimage_shape=(128,128,128)ell_center=(64,64,64)ell_radii=(5,50,30)ell_angles=np.deg2rad([80,30,20])image=drawing.make_ellipsoid_image(image_shape,ell_center,ell_radii,ell_angles)# Compute inertia ellipsoidpoints=analysis.sample_random_points(image)inertia_ellipsoid=analysis.compute_inertia_ellipsoid(points)

要旋转轴并查找原始轴和旋转轴之间的相对旋转:

importnumpyasnpfrompyellipsoidimportgeometryoriginal_axes=np.array([[1,0,0],[0,1,0],[0,0,1]])rot_angles=np.deg2rad([0,0,45])# Rotate around Z-axis by 45 deg# Build rotation matrix and rotate the axesrotm=geometry.build_rotation_matrix(*rot_angles)rotated_axes=np.dot(rotm,np.transpose(original_axes)).T# Find relative rotationrel_rotm=geometry.find_relative_axes_rotation(original_axes,rotated_axes)# Validate relative rotation matrixrel_rotated_axes=np.dot(rel_rotm,np.transpose(original_axes)).Tassert(np.all(rotated_axes==rel_rotated_axes))# Compute rotation angles# Please note, that these angles might differ from rot_angles!rel_rot_angles=geometry.rotation_matrix_to_angles(rel_rotm)print(np.rad2deg(rel_rot_angles))

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

推荐PyPI第三方库


热门话题
Spring 4升级后未加载java应用程序上下文   java Android 2.3.3 internet可以在我的Galaxy S上运行,但不能在我的Galaxy选项卡上运行?(许可?)   java通过不改变其原始位置对大小写字母进行排序   java Spring Boot一直在破坏我的电脑。。。sts的最佳配置是什么。Windows 10上的ini文件?   css Java Spring+引导问题   java Jackson将GeoJsonPoint序列化为纬度/经度   xml Java Transformer:如何将其结果生成OutputStream?   java如何更改字体、文本大小和设置文本位置?   在JavaSpringHibernate3.6.3中,如何告诉一个方法等待,直到获得锁,以及如何重试失败的事务?   java安卓服务代替线程   Java Swing使用鼠标移动JFrame