图像配准-弹性变换利用Python库-PyElastix快速实现弹性配准

b站视频地址:

一. 环境准备

系统选择:Windows、mac、Linux均可

准备步骤:

  • 安装Pyelastix库 pip install pyelastix or conda install pyelastix -c conda-forge
  • 下载Elastix执行文件并配置到系统路径
  • 开始使用

其中下载Elastix执行文件并配置到系统路径步骤如下:
进入官网:https://elastix.lumc.nl/,下载对应系统的文件

Windows系统:

  1. 解压下载好的文件
  2. 将文件夹复制到C盘Program FilesProgram Files (*86)路径下

Linux/Mac

  1. 解压下载好的文件
  2. 添加路径到系统变量
vim ~/.bashrc
export EKASTIX_PATH=/path/bin/elastix:$ELASTIX_PATH
export LD_LIBRARY=/path/lib:$LD_LIBRARY

至此环境配置完成

二、开始使用

完整代码如下

# 导包
import pyelastix
import imageio
import matplotlib.pyplot as plt
import cv2 as cv

# 读取数据
im1 = imageio.imread('chelsea.png')
im2 = imageio.imread('chelsea_morph1.png')

# 选择一个通道,转为浮点型
im1 = im1[:,:,1].astype('float32')
im2 = im2[:,:,1].astype('float32')

# 调用pyelastix库中的get_default_params方法获取默认参数值,主要参数:
# NumberOfResolutions(int)
# MaximumNumberOfIterations (int)
# MaximumNumberOfIterations (int)等
# 通过 params.变量名来设置参数值
params = pyelastix.get_default_params()
params.NumberOfResolutions = 3
print(params)

# 开始配准,register(浮动图像,参考图像,上面设置的变量)
im3, field = pyelastix.register(im1, im2, params)

# 可视化结果
fig = plt.figure(1);
plt.clf()
plt.subplot(231); plt.imshow(im1)
plt.subplot(232); plt.imshow(im2)
plt.subplot(234); plt.imshow(im3)
plt.subplot(235); plt.imshow(field[0])
plt.subplot(236); plt.imshow(field[1])
# 保存结果
cv2.imwrite('filename.jpg',im3)
# Enter mainloop
if hasattr(plt, 'use'):
    plt.use().Run()  # visvis
else:
    plt.show()  # mpl

在这里插入图片描述
moving_image

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MaybeRichard

请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值