1. 样例数据
ori_file = '1.nii.gz'
  1. 使用sampleITK读取数据,注意SimpleITK 加载数据是channel_first。
import SimpleITK as sitk
ds = sitk.ReadImage(file)
img_array = sitk.GetArrayFromImage(ds)
np.shape(img_array)

(229, 512, 512)

channel为229。

  1. 查看图像的原点Origin,大小Size,间距Spacing和方向Direction。
print(ds.GetOrigin())
print(ds.GetSize())
print(ds.GetSpacing())
print(ds.GetDirection())

(-249.51171875, -442.51171875, -610.5999755859375)
(512, 512, 229)
(0.9765625, 0.9765625, 2.0)
(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,1.0)

  1. 查看图像相关的纬度信息
print(ds.GetDimension())
print(ds.GetWidth())
print(ds.GetHeight())
print(ds.GetDepth())

3
512
512
229

  1. 体素类型查询
print(ds.GetPixelIDValue())
print(ds.GetPixelIDTypeAsString())
print(ds.GetNumberOfComponentsPerPixel())

2
16-bit signed integer
1

  1. 查看某一个横断面和冠状面
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize = (10, 5))
ax1.imshow(img_array[150,:,:], cmap=plt.cm.bone)
ax1.set_title('T')
ax2.imshow(img_array[:,150,:], cmap=plt.cm.bone)
ax2.set_title('C')
ax3.imshow(img_array[:,:,100], cmap=plt.cm.bone)
ax3.set_title('S')


7. Resampling
将space:(0.9765625,0.9765625,2.0)−−−>(1,1,1)space: (0.9765625, 0.9765625, 2.0) ---> (1, 1,1)space:(0.9765625,0.9765625,2.0)−−−>(1,1,1)

def ImageResample(sitk_image, new_spacing = [1.0, 1.0, 1.0], is_label = False):'''sitk_image:new_spacing: x,y,zis_label: if True, using Interpolator `sitk.sitkNearestNeighbor`'''size = np.array(sitk_image.GetSize())spacing = np.array(sitk_image.GetSpacing())new_spacing = np.array(new_spacing)new_size = size * spacing / new_spacingnew_spacing_refine = size * spacing / new_sizenew_spacing_refine = [float(s) for s in new_spacing_refine]new_size = [int(s) for s in new_size]resample = sitk.ResampleImageFilter()resample.SetOutputDirection(sitk_image.GetDirection())resample.SetOutputOrigin(sitk_image.GetOrigin())resample.SetSize(new_size)resample.SetOutputSpacing(new_spacing_refine)if is_label:resample.SetInterpolator(sitk.sitkNearestNeighbor)else:#resample.SetInterpolator(sitk.sitkBSpline)resample.SetInterpolator(sitk.sitkLinear)newimage = resample.Execute(sitk_image)return newimage
nor = ImageResample(ds)
nor.GetSize()
  1. 打印Resampling之后的图像

  1. 3D plot
import scipy.ndimage
import matplotlib.pyplot as pltfrom skimage import measure, morphology
from mpl_toolkits.mplot3d.art3d import Poly3DCollectiondef plot_3d(image, threshold=-300):# Position the scan upright, # so the head of the patient would be at the top facing the cameraimage = image.astype(np.int16)p = image.transpose(2,1,0)
#     p = p[:,:,::-1]print(p.shape)verts, faces, _, x = measure.marching_cubes_lewiner(p, threshold) #marching_cubes_classic measure.marching_cubesfig = plt.figure(figsize=(10, 10))ax = fig.add_subplot(111, projection='3d')# Fancy indexing: `verts[faces]` to generate a collection of trianglesmesh = Poly3DCollection(verts[faces], alpha=0.1)face_color = [0.5, 0.5, 1]mesh.set_facecolor(face_color)ax.add_collection3d(mesh)ax.set_xlim(0, p.shape[0])ax.set_ylim(0, p.shape[1])ax.set_zlim(0, p.shape[2])plt.show()
plot_3d(nor_data, 100)

参考

  1. https://www.kaggle.com/akh64bit/full-preprocessing-tutorial
  2. http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/03_Image_Details.html

【SimpleITK】胸部CT数据3D space归一化,以及3D plot相关推荐

  1. 教您用CT数据和桌面3D打印机打印自己的器官模型

    这已经不是什么秘密了,3D打印应用目前正在医学界高歌猛进.我们已经看到了一些突破性的3D打印假肢.植入物,而且在未来几年内各种生物医学3D打印解决方案(甚至是3D打印器官!)都有望出现. 但是您知道如 ...

  2. 5分钟内完成胸部CT扫描机器学习

    This post provides an overview of chest CT scan machine learning organized by clinical goal, data re ...

  3. MosMedData: 新冠肺炎胸部 CT扫描数据集上基于3D-CNN实现二分类

    MosMedData: 新冠肺炎胸部 CT扫描数据集上基于3D-CNN实现二分类 作者: WangXi2016 日期: 2022.10.27 摘要: 本示例教程使用3D CNN实现CT数据二分类. 1 ...

  4. 一文带你解读:卷积神经网络自动判读胸部CT图像的机器学习原理

    本文介绍了利用机器学习实现胸部CT扫描图像自动判读的任务,这对我来说是一个有趣的课题,因为它是我博士论文研究的重点.这篇文章的主要参考资料是我最近的预印本 "Machine-Learning ...

  5. 【影像组学】CT数据与MRI数据

    [影像组学]CT数据与MRI数据 一.CT :计算机断层成像技术 1.工作流程 根据人体不同组织对X线的吸收与透过率的不同,应用灵敏度极高的仪器对人体进行测量,然后将测量所获取的数据输入电子计算机,电 ...

  6. 体素二值膨胀求解采样空间 binary voxel dilation in 3D space

    体素二值膨胀 binary voxel dilation in 3D space 前言 1 二值膨胀 2 体素二值膨胀 2.1 难点 2.2 基于ndimage.binary_dilation()编写 ...

  7. cufflinks基于dataframe数据绘制三维散点图(3d scatter plot)

    cufflinks基于dataframe数据绘制三维散点图(3d scatter plot) 查看df.iplot对应的各种自定义参数,在jupyter notebook中输入如下信息: df.ipl ...

  8. 数据标准化(归一化)

    数据标准化(归一化)处理是数据挖掘的一项基础工作,不同评价指标往往具有不同的量纲和量纲单位,这样的情况会影响到数据分析的结果,为了消除指标之间的量纲影响,需要进行数据标准化处理,以解决数据指标之间的可 ...

  9. Scikit-learn 数据预处理之归一化MinMaxScaler

    Scikit-learn 数据预处理之归一化MinMaxScaler 1 声明 本文的数据来自网络,部分代码也有所参照,这里做了注释和延伸,旨在技术交流,如有冒犯之处请联系博主及时处理. 2 MinM ...

  10. python归一化sklearn_用sklearn进行对数据标准化、归一化以及将数据还原详解

    如何用sklearn进行对数据标准化.归一化以及将数据还原 在对模型训练时,为了让模型尽快收敛,一件常做的事情就是对数据进行预处理. 这里通过使用sklearn.preprocess模块进行处理. 一 ...

最新文章

  1. s-stat 查看文件或者文件系统的状态信息
  2. linux c 获取屏幕信息,Linux C 获取本机相关信息
  3. Cloudify — Plugins
  4. 3.6 Git 分支 - 分支的衍合
  5. 高版本glibc环境编译兼容低版本机器的.so文件
  6. docker 每次都得source /etc/profile以及如何查看Docker容器环境变量、向容器传递环境变量
  7. MetadataType的使用
  8. Java学习小程序(2)输出三个数中的最大值
  9. code blocks代码性能分析_Julia系列教程13--如果写出高性能的Julia代码
  10. Foundation框架集合 ---- NSArray和NSMutableArray
  11. 网络运维在经济危机中茁壮成长
  12. Visual studio 2010 中文SP1 无法安装Silverlight5 Beta Tools的解决办法
  13. 软工网络15个人阅读作业1
  14. 拇指接龙游戏中的Undo道具与STL容器deque简介
  15. Mac如何解决vi vim光标移动慢问题
  16. Sketch项目安装缺失字体
  17. SQL删除字段重复内容且保留唯一一条数据
  18. acdsee 15中文版的许可证密钥+激活方法
  19. 杨强教授新番!破解机器学习数据孤岛和数据保护难题
  20. 人艰不拆——记在工作一个半月之后

热门文章

  1. 【转】如何学会独立思考?
  2. (Twinkle Tray)快速调整外接显示器屏幕亮度
  3. 使用hiredis接口(Synchronous API)编写redis流水线客户端
  4. 通过反射访问private的属性或方法
  5. Python全栈(第一部分)day1
  6. java.io.IOException: Could not find status of job:job_1534233312603_0002
  7. 黑板课爬虫闯关之关卡二
  8. checkbox属性checked=checked已有,但却不显示打勾的解决办法
  9. Android ListView显示底部的分割线
  10. echo print printf() sprintf()区别