当前位置:网站首页>医学图像数据增强-重采样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) # 得到重新采样后的图像
边栏推荐
- 《预训练周刊》第56期:长文本理解、即时问答、掩码自监督
- Verilog HDL Bits training 09 grammar foundation
- poj3744 Scout YYF I
- 如果Controller里有私有的方法,能成功访问吗?
- poj2096 Collecting Bugs
- Tensorflow与Keras进行机器学习、深度学习
- 连锁小酒馆第一股,海伦司能否梦圆大排档?
- [C language] Dynamic memory management
- R语言ggplot2可视化:使用ggpubr包的ggdonutchart函数可视化甜甜圈图(donut chart)、为甜甜圈图添加自定义标签(包含文本内容以及数值百分比)、lab.font参数设置标
- 树上距离为1子集修改
猜你喜欢
KD-SCFNet: More Accurate and Efficient Salient Object Detection Through Knowledge Distillation (ECCV2022)
京东三面惨遭被虐,关于redis,高并发,分布式,问懵了
[界面开发]DevExpress WinForms流程图控件——XtraDiagrams组件入门指南
干货满满,中科院信工所于静新课帮你get学术研究与论文写作技能
[8月4日]剑指 Offer 52. 两个链表的第一个公共节点
【Rust—LeetCode题解】1.两数之和
HackTheBox | Horizontall
KMP Media Group South Africa implemented a DMS (Document Management System) to digitize the process, employees can again focus on their actual tasks, providing efficiency
【JS高级】ES5标准规范之严格模式下的保护对象_09
译文推荐|深入解析 BookKeeper 协议模型与验证
随机推荐
R语言基于指定规则、条件删除列表中的元素:使用purrr包的discard函数移除列表数据中的NA值
R语言使用位置索引筛选dataframe的数据列:筛选单个数据列、筛选多个数据列、列表表达式方法、矩阵式下标方法
[Redis] Redis installation and use of client redis-cli (batch operation)
Verilog HDL Bits training 09 grammar foundation
poj2096 Collecting Bugs
bzoj 3624 [Apio2008]免费道路
使用.NET简单实现一个Redis的高性能克隆版(三)
Server Configuration - Install Redis on Linux System
Photoshop插件-charIDToTypeID-PIStringTerminology.h-不同值的解释及参考-脚本开发-PS插件
Tsinghua | GLM-130B: An Open Bilingual Pre-training Model
如何对用户输入进行校验
R语言ggplot2可视化:使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tab_add_hline函数为表头添加横线并自定义线条宽度
连锁小酒馆第一股,海伦司能否梦圆大排档?
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
(5) FlinkSQL writes socket data to mysql Method 2
基于FPGA的FIR滤波器的实现(1)—采用fir1函数设计
医药行业转型发展,探索数字化供应链升级之道
Harvard University smashes the field: DALL-E 2 is just a "glue monster", and the generation accuracy rate is only 22%
使用shardingjdbc实现读写分离配置
UnsatisfiedDependencyException: Error creating bean with name ‘