本文为转载文章,原文链接

  • 通用约定

  • 基本图像属性:

image_3D = sitk.Image(256, 128, 64, sitk.sitkInt16)
image_2D = sitk.Image(64, 64, sitk.sitkFloat32)
image_2D = sitk.Image([32,32], sitk.sitkUInt32)
image_RGB = sitk.Image([128,64], sitk.sitkVectorUInt8, 3)
print image.GetSize()
print image.GetOrigin()
print image.GetSpacing()
print image.GetDirection()
print image.GetNumberOfComponentsPerPixel()
print(image_3D.GetDimension())
print(image_3D.GetWidth())
print(image_3D.GetHeight())
print(image_3D.GetDepth())
print(image_3D.GetPixelIDValue())
print(image_3D.GetPixelIDTypeAsString())
print(image_3D.GetNumberOfComponentsPerPixel())
print(image_RGB.GetDimension())
print(image_RGB.GetSize())
print(image_RGB.GetNumberOfComponentsPerPixel())
print(image_2D.GetSize())
print(image_2D.GetDepth())

  • 图像操作
img1 = sitk.Image(24,24, sitk.sitkUInt8)
img1[0,0] = 0img2 = sitk.Image(img1.GetSize(), sitk.sitkUInt8)
img2.SetDirection([0,1,0.5,0.5])
img2.SetSpacing([0.5,0.8])
img2.SetOrigin([0.000001,0.000001])
img2[0,0] = 255img3 = img1 + img2
print(img3[0,0])
  • 访问和索引切片

Slicing of SimpleITK images returns a copy of the image data.
This is similar to slicing Python lists and differs from the “view” returned by slicing numpy arrays.

  • numpy的和SimpleITK之间的转换:

SimpleITK和numpy的索引访问的顺序相反!
SimpleITK:图像[X,Y,Z]
numpy的:image_numpy_array [Z,Y,X]

1. 从SimplTK到numpy

2. 从numpy到SimpleITK

3. 区别于scikit-image和numpy的转换:

  • 读写图像

SimpleITK可以读写存储在单个文件或一组文件(例如DICOM系列)中的图像。

以DICOM格式存储的图像具有与之关联的元数据字典,其中包括了DICOM标签。当将DICOM系列被读为单个图像时,元数据信息不可用,因为DICOM标签是针对每个单独文件的。如果需要元数据,可以使用面向对象的接口的ImageSeriesReader类,或者ImageFileReader类,设置特定切片的文件名,访问元数据图像使用GetMetaDataKeys,HasMetaDataKey和GetMetaData。

例如,读取DICOM格式的图像,并将其写为mhd。文件格式由文件扩展名推导出。还设置了适当的像素类型-您可以覆盖它并强制选择您要的像素类型。

data_directory = os.path.dirname(fdata("CIRS057A_MR_CT_DICOM/readme.txt"))
series_ID = '1.2.840.113619.2.290.3.3233817346.783.1399004564.515'# Get the list of files belonging to a specific series ID.
reader = sitk.ImageSeriesReader()
# Use the functional interface to read the image series.
original_image = sitk.ReadImage(reader.GetGDCMSeriesFileNames(data_directory, series_ID))# Write the image.
output_file_name_3D = os.path.join(OUTPUT_DIR, '3DImage.mha')
sitk.WriteImage(original_image, output_file_name_3D)# Read it back again.
written_image = sitk.ReadImage(output_file_name_3D)# Check that the original and written image are the same.
statistics_image_filter = sitk.StatisticsImageFilter()
statistics_image_filter.Execute(original_image - written_image)# Check that the original and written files are the same
print('Max, Min differences are : {0}, {1}'.format(statistics_image_filter.GetMaximum(), statistics_image_filter.GetMinimum()))

Fetching CIRS057A_MR_CT_DICOM/readme.txt
Max, Min differences are : 0.0, 0.0

将图像写为jpg格式,并且需要重新调整图像强度(默认为[0,255]),因为JPEG格式的显示需要转换为UInt8像素类型。

sitk.WriteImage(sitk.Cast(sitk.RescaleIntensity(written_image), sitk.sitkUInt8), [os.path.join(OUTPUT_DIR, 'slice{0:03d}.jpg'.format(i)) for i in range(written_image.GetSize()[2])]) 
  • 图像显示

尽管SimpleITK不进行可视化,但确实包含一个内置Show方法。此功能将映像写出到磁盘,然后启动程序进行可视化。默认情况下,它配置为使用ImageJ,因为它很容易支持许多医学图像格式并快速加载。但是,Show可视化程序可以通过环境变量轻松自定义:

SITK_SHOW_COMMAND:要使用的查看器(ITK-SNAP,3D Slicer …)
SITK_SHOW_COLOR_COMMAND:显示彩色图像时使用的查看器。
SITK_SHOW_3D_COMMAND:用于3D图像的查看器。

img = reader.Execute()
# Display the image slice from the middle of the stack, z axis
z = int(img.GetDepth()/2)
plt.imshow(sitk.GetArrayViewFromImage(img)[z,:,:], cmap=plt.cm.Greys_r)
plt.axis('off');

mr_image = sitk.ReadImage(fdata('training_001_mr_T1.mha'))
npa = sitk.GetArrayViewFromImage(mr_image)# Display the image slice from the middle of the stack, z axis
z = int(mr_image.GetDepth()/2)
npa_zslice = sitk.GetArrayViewFromImage(mr_image)[z,:,:]# Three plots displaying the same data, how do we deal with the high dynamic range?
fig = plt.figure()
fig.set_size_inches(15,30)fig.add_subplot(1,3,1)
plt.imshow(npa_zslice)
plt.title('default colormap')
plt.axis('off')fig.add_subplot(1,3,2)
plt.imshow(npa_zslice,cmap=plt.cm.Greys_r);
plt.title('grey colormap')
plt.axis('off')fig.add_subplot(1,3,3)
plt.title('grey colormap,\n scaling based on volumetric min and max values')
plt.imshow(npa_zslice,cmap=plt.cm.Greys_r, vmin=npa.min(), vmax=npa.max())
plt.axis('off');

参考:

【1】SimpleITK图像基础
【2】SimpleITK-Notebooks-03_Image_Details
【3】scikit-image中的numpy速成
【4】SITK Documentation docs

SimpleITK图像基础相关推荐

  1. SimpleITK图像基础(三)——SimpleITK学习笔记

    SimpleITK学习笔记 前言 1 sitk中的常见属性值 2 读取和保存图像 3 像素类型 4 SimpleITK图像数据和Numpy矩阵数据之间的转换 5 访问像素和切片 6 图像重采样 7 图 ...

  2. 【Matlab 图像】图像基础操作

    图像基础操作 读取图片 读取视频 读取图片 % 读取图像 Img = imread('test2.png'); subplot(2,2,1); imshow(Img); title('原图(RGB图) ...

  3. CV:计算机视觉技术之图像基础知识(二)—图像内核的可视化解释

    CV:计算机视觉技术之图像基础知识(二)-图像内核的可视化解释 目录 图像内核的可视化解释 测试九种卷积核 官方Demo DIY图片测试 DIY实时视频测试 相关文章 CV:计算机视觉技术之图像基础知 ...

  4. CV:计算机视觉技术之图像基础知识(二)—以python的skimage和numpy库来了解计算机视觉图像基础(图像存储原理-模糊核-锐化核-边缘检测核,进阶卷积神经网络(CNN)的必备基础)

    CV:计算机视觉技术之图像基础知识(二)-以python的skimage和numpy库来了解计算机视觉图像基础(图像存储原理-模糊核-锐化核-边缘检测核,进阶卷积神经网络(CNN)的必备基础) 目录 ...

  5. CV:计算机视觉技术之图像基础知识—以python的cv2库来了解计算机视觉图像基础

    CV:计算机视觉技术之图像基础知识-以python的cv2库来了解计算机视觉图像基础 目录 一.图像中的傅里叶变换 1.时域和频域 2.傅里叶变换 3.图像中的傅里叶变换

  6. CV:计算机视觉技术之图像基础知识(一)—以python的cv2库来了解计算机视觉图像基础(傅里叶变换-频域-时域/各种滤波器-线性-非线性-均值-中值-高斯-双边)

    CV:计算机视觉技术之图像基础知识(一)-以python的cv2库来了解计算机视觉图像基础(傅里叶变换-频域-时域/各种滤波器-线性-非线性-均值-中值-高斯-双边) 目录 一.图像中的傅里叶变换 1 ...

  7. 【AI白身境】深度学习必备图像基础

    文章首发于微信公众号<有三AI> [AI白身境]深度学习必备图像基础 今天是新专栏<AI白身境>的第四篇,所谓白身,就是什么都不会,还没有进入角色. 我们已经说了linux基础 ...

  8. 数字图像处理之图像基础

    最近在学数字图像处理,图像基础包括以下部分: 导入库 import numpy as np import matplotlib.pyplot as plt import cv2 as cv 图片展示函 ...

  9. OpenCV与图像处理学习一——图像基础知识、读入、显示、保存图像、灰度转化、通道分离与合并

    OpenCV与图像处理学习一--图像基础知识.读入.显示.保存图像.灰度转化.通道分离与合并 一.图像基础知识 1.1 数字图像的概念 1.2 数字图像的应用 1.3 OpenCV介绍 二.图像属性 ...

最新文章

  1. java验证码源码_Java通用验证码程序及应用示例(提供源码下载)
  2. 设置共享,实现Linux和Windows之间的共享
  3. Springmvc的helloworld实例
  4. 服务提供商应该如何帮助企业保护数据安全
  5. TortoiseGit 将工作区变动文件提交本地仓库_入门试炼_04
  6. vmware虚拟机磁盘挂载
  7. 艾伟:如何实现用返回值重载
  8. 朝鲜黑客伪装成三星招聘人员诱骗安全研究员,或发动供应链攻击
  9. C++解析(31):自定义内存管理(完)
  10. 一种新的人机交流方式——sound ware 声件
  11. 2011年度IT博客大赛 “博”乐大行动(已结束)
  12. hadoop与hive
  13. 常用电子元器件检测方法与经验
  14. 时频分析方法及其在发展性EEG数据中的应用
  15. 【组合数学】 放小球之隔板法
  16. windows/ubuntu系统下安装teamview教程
  17. 解决linux kernel 提交gerrit时,运行checkpatch.pl产生的xxxx64_defconfig not generated by savedefconfig问题
  18. dell服务器显示器fre,戴尔全新 Freesync 显示器,专门针对游戏玩家
  19. 强哥日常高效工作流骨灰级玩家培训课程
  20. systemd工具介绍

热门文章

  1. 从YOLOv1到v3的进化之路
  2. Ubuntu16.04+Theano环境
  3. ANSI/CAN/UL 1973:2022 固定和运动辅助电源用电池安规要求-最新的英文2022完整版{135页}
  4. 电子招投标系统简介 招投标系统源码 java招投标系统开发类型 招投标系统功能设计
  5. php imagick 安装,win10_php_imagick 扩展的安装
  6. iOS开发-植入广告(iAd, Admob实例)
  7. 启动mysql数据库是红色_Mysql无法启动
  8. 编译错误:commands commence before first target
  9. 代码在线高亮工具[写源代码的word可用]
  10. JS跨域使用jsonp