当前位置:网站首页>医学图像数据增强-重采样itk
医学图像数据增强-重采样itk
2022-08-08 13:44:00 【智能之心】
resample_augmentations.py
def resample_image_itk(
ori_img,
new_spacing=[1.0,1.0,1.0],
new_size=[0,0,0],
resamplemethod=sitk.sitkNearestNeighbor):
"""
@Args:
:param ori_img: 原始需要对齐的itk图像
:param new_spacing: 111
:param new_size: 默认000, 注意非零则自动裁剪
:param resamplemethod:
sitk.sitkLinear-线性 - image
sitk.sitkNearestNeighbor-最近邻 -mask
@Return:
重采样好的itk图像
"""
ori_size = ori_img.GetSize() # 原始图像大小 [x,y,z]
ori_spacing = ori_img.GetSpacing() # 原始的体素块尺寸 [x,y,z]
ori_origin = ori_img.GetOrigin() # 原始的起点 [x,y,z]
ori_direction = ori_img.GetDirection() # 原始的方向 [冠,矢,横]=[z,y,x]
# 计算改变spacing后的size,用物理尺寸/体素的大小
if new_size==[0,0,0]:
new_size[0] = int(ori_size[0]*ori_spacing[0]/new_spacing[0] + 0.5)
new_size[1] = int(ori_size[1]*ori_spacing[1]/new_spacing[1] + 0.5)
new_size[2] = int(ori_size[2]*ori_spacing[2]/new_spacing[2] + 0.5)
# itk的方法进行resample
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(ori_img) # 需要重新采样的目标图像
# 设置目标图像的信息
resampler.SetSize(new_size) # 目标图像大小
resampler.SetOutputOrigin(ori_origin)
resampler.SetOutputDirection(ori_direction)
resampler.SetOutputSpacing(new_spacing)
# 根据需要重采样图像的情况设置不同的dype
if resamplemethod == sitk.sitkNearestNeighbor:
resampler.SetOutputPixelType(sitk.sitkUInt16) # 近邻插值用于mask的,保存uint16
else:
resampler.SetOutputPixelType(sitk.sitkFloat32) # 线性插值用于PET/CT/MRI之类的,保存float32
resampler.SetTransform(sitk.Transform(3, sitk.sitkIdentity))
resampler.SetInterpolator(resamplemethod)
return resampler.Execute(ori_img) # 得到重新采样后的图像
边栏推荐
猜你喜欢
随机推荐
基于Nodejs的医生预约平台的设计和实现
keil5——安装教程附资源包
使用单点登录 (SSO):便捷访问,降低风险,精简流程
[C language] Dynamic memory management
【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
Tensorflow and Keras for machine learning, deep learning
难产的“第一股”:中式快餐之困
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
数据解析(XPath、BeautifulSoup、正则表达式、pyquery)
poj3744 Scout YYF I
直接选择排序
Pretraining Weekly Issue 56: Long Text Understanding, Instant Question Answering, Mask Self-Supervision
Program Environment and Preprocessing
MySQL:索引(1)原理与底层结构
TS+Hooks二次封装antd Modal,实现可拖拽
idea增加左右箭头
【低代码】1405- 浅谈低代码平台远程组件加载方案
Qt操作Sqlite类封装,及命令行导入csv文件到Sqlite数据库
idea中项目呈现树形结构
Prometheus监控Harbor(二进制版)