imagej/fiji插件turboreg/stackreg的python实现

pystackreg的Python项目详细描述


摘要

Python/C++端口,由菲利普·戴维纳斯/ EPFL编写。

用于将源图像或堆栈(电影)自动对齐到目标图像/参考帧的python扩展。

说明

pystackreg用于将一个或多个图像与一个公共参考图像对齐(注册),这在时间分辨荧光显微镜或广域显微镜中通常是必需的。它直接从imagej插件TurboReg的源代码中移植,并提供imagej插件StackReg的功能,这两个插件都是由philippe thevenaz/epfl编写的(可在http://bigwww.epfl.ch/thevenaz/turboreg/获得)。

pystackreg提供了以下四种类型的失真:

  • 翻译
  • 刚体(平移+旋转)
  • 缩放旋转(平移+旋转+缩放)
  • 仿射(平移+旋转+缩放+剪切)
  • 双线性(非线性变换;不保留直线)

pystackreg支持stackreg的全部功能以及一些附加选项,例如,使用不同的参考图像和访问实际的转换矩阵(请参见下面的示例)。

请注意:双线性变换不能传播,因为双线性变换的组合通常不会导致双线性变换。因此,当使用“上一个”图像作为参考图像时,堆栈注册/转换函数不能与双线性转换一起工作。您可以使用另一个引用(“第一”或“平均”分别用于第一个或平均图像),或者尝试将堆栈的每个图像分别注册/转换为其各自的前一个图像(并将已转换的前一个图像用作下一个图像的引用)。

安装

pypi上提供了这个包。使用:

pipinstallpystackreg

文档

文档可在“已读文档”中找到:

https://pystackreg.readthedocs.io/

用法

下面的示例打开两个不同的文件,并使用所有不同的可能转换来注册它们

frompystackregimportStackRegfromskimageimportio#load reference and "moved" imageref=io.imread('some_original_image.tif')mov=io.imread('some_changed_image.tif')#Translational transformationsr=StackReg(StackReg.TRANSLATION)out_tra=sr.register_transform(ref,mov)#Rigid Body transformationsr=StackReg(StackReg.RIGID_BODY)out_rot=sr.register_transform(ref,mov)#Scaled Rotation transformationsr=StackReg(StackReg.SCALED_ROTATION)out_sca=sr.register_transform(ref,mov)#Affine transformationsr=StackReg(StackReg.AFFINE)out_aff=sr.register_transform(ref,mov)#Bilinear transformationsr=StackReg(StackReg.BILINEAR)out_bil=sr.register_transform(ref,mov)

下一个示例演示如何将注册与转换分离(例如,在一个颜色通道中注册,然后使用该信息转换另一个颜色通道):

frompystackregimportStackRegfromskimageimportioimg0=io.imread('some_multiframe_image.tif')img1=io.imread('another_multiframe_image.tif')# img0.shape: frames x width x height (3D)sr=StackReg(StackReg.RIGID_BODY)# register 2nd image to 1stsr.register(img0[0,:,:],img0[1,:,:])# use the transformation from the above registration to register another frameout=sr.transform(img1[1,:,:])

下面的示例演示如何注册和转换整个堆栈:

frompystackregimportStackRegfromskimageimportioimg0=io.imread('some_multiframe_image.tif')# 3 dimensions : frames x width x heightsr=StackReg(StackReg.RIGID_BODY)# register each frame to the previous (already registered) one# this is what the original StackReg ImageJ plugin usesout_previous=sr.register_transform_stack(img0,reference='previous')# register to first imageout_first=sr.register_transform_stack(img0,reference='first')# register to mean imageout_mean=sr.register_transform_stack(img0,reference='mean')# register to mean of first 10 imagesout_first10=sr.register_transform_stack(img0,reference='first',n_frames=10)# calculate a moving average of 10 images, then register the moving average to the mean of# the first 10 images and transform the original image (not the moving average)out_moving10=sr.register_transform_stack(img0,reference='first',n_frames=10,moving_average=10)

下一个示例演示如何将堆栈的注册与转换分离(例如,在一个颜色通道中注册,然后使用该信息转换另一个颜色通道):

frompystackregimportStackRegfromskimageimportioimg0=io.imread('some_multiframe_image.tif')# 3 dimensions : frames x width x heightimg1=io.imread('another_multiframe_image.tif')# same shape as img0# both stacks must have the same shapeassertimg0.shape==img1.shapesr=StackReg(StackReg.RIGID_BODY)# register each frame to the previous (already registered) one# this is what the original StackReg ImageJ plugin usestmats=sr.register_stack(img0,reference='previous')out=sr.transform_stack(img1)# tmats contains the transformation matrices -> they can be saved# and loaded at another timeimportnumpyasnpnp.save('transformation_matrices.npy',tmats)tmats_loaded=np.load('transformation_matrices.npy')# make sure you use the correct transformation here!sr=StackReg(StackReg.RIGID_BODY)# transform stack using the tmats loaded from filesr.transform_stack(img1,tmats=tmats_loaded)# with the transformation matrices at hand you can also# use the transformation algorithms from other packages:fromskimageimporttransformastfout=np.zeros(img0.shape).astype(np.float)foriinrange(tmats.shape[0]):tform=tf.AffineTransform(matrix=tmats[i,:,:])out[i,:,:]=tf.warp(img1[i,:,:],tform)

作者信息

这是Philippe Thevenaz的原始Java代码的一个端口,用Python包装器围绕它。所有功劳归于原作者:

/*====================================================================
| Philippe Thevenaz
| EPFL/STI/IMT/LIB/BM.4.137
| Station 17
| CH-1015 Lausanne VD
| Switzerland
|
| phone (CET): +41(21)693.51.61
| fax: +41(21)693.37.01
| RFC-822: philippe.thevenaz@epfl.ch
| X-400: /C=ch/A=400net/P=switch/O=epfl/S=thevenaz/G=philippe/
| URL: http://bigwww.epfl.ch/
\===================================================================*/

/*====================================================================
| This work is based on the following paper:
|
| P. Thevenaz, U.E. Ruttimann, M. Unser
| A Pyramid Approach to Subpixel Registration Based on Intensity
| IEEE Transactions on Image Processing
| vol. 7, no. 1, pp. 27-41, January 1998.
|
| This paper is available on-line at
| http://bigwww.epfl.ch/publications/thevenaz9801.html
|
| Other relevant on-line publications are available at
| http://bigwww.epfl.ch/publications/
\===================================================================*/

许可证

以下是TurboReg/StackReg的许可证:

/*====================================================================
| Additional help available at http://bigwww.epfl.ch/thevenaz/turboreg/
|
| You'll be free to use this software for research purposes, but you
| should not redistribute it without our consent. In addition, we expect
| you to include a citation or acknowledgment whenever you present or
| publish results that are based on it.
\===================================================================*/

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

推荐PyPI第三方库


热门话题
java Android使用两个后台服务错误   解压缩HTTPInputStream时,java GZIPInputStream过早关闭   javax和javax的区别是什么。网ssl。密钥库和服务器。ssl。为SpringBoot应用程序指定密钥库时的密钥库属性   java生成两个JPanel,而我只需要一个   java深度链接从play store安装应用程序时获取数据   java 安卓应用程序在退出时未正确释放蓝牙   java正确使用setCellValueFactory   java开放JdbcTemplate连接处于只读模式?   使用Spring MVC创建服务时发生java错误   JavaFX获取安装在计算机中的特定应用程序的版本   SecureRandom的安全问题:PRNG在java 1.5中不一致   windows我可以创建一个独立的。带Inno设置的Java应用程序的exe安装程序?   如何使用JavaServlet下载csv文件?   java从生成的缓冲图像中添加图像作为jasper中的数据记录?   java日期和时间解析