当前位置: 首页 > 工具软件 > SimpleBox > 使用案例 >

【9】simpleitk和OpenCV处理医学图像流程

端木鹏
2023-12-01

【1】simpleitk打开,OpenCV处理

simpleitk打开dcm格式的数据,通常是一个序列,随后转换为三维数组,然后采用OpenCV处理单个界面的图形(二维操作),随后保存到三维矩阵中,最后导出三维矩阵,设置格式。


# here put the import lib


import numpy as np
import SimpleITK as sitk
import cv2
import copy


path="F:\mediacldata\dcmimage\series-000001"

#s1 载入dcm序列图像
reader = sitk.ImageSeriesReader()
dicom = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom)
image = reader.Execute()
img_array = sitk.GetArrayFromImage(image)
sitk.WriteImage(image,"01.mha")

#s2 opencv处理横断面图像(也可以采用simpleitk库处理)
for index in range(img_array.shape[0]):
    img=np.array(img_array[index,:,:],dtype=np.uint8)
    img1=cv2.equalizeHist(img)
    img_array[index,:,:]=copy.deepcopy(img1)

#s3 OpenCV处理结果保存
dcmimg= sitk.GetImageFromArray(img_array)
sitk.WriteImage(dcmimg,"equalizehist.mha")    

【2】simpleitk处理


# here put the import lib


import numpy as np
import SimpleITK as sitk
import cv2
import copy


path="F:\mediacldata\dcmimage\series-000001"

#s1 载入dcm序列图像
reader = sitk.ImageSeriesReader()
dicom = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom)
image = reader.Execute()
sitk.WriteImage(image,"01.mha")

#img_array = sitk.GetArrayFromImage(image)
#s2 opencv处理横断面图像(也可以采用simpleitk库处理)
# for index in range(img_array.shape[0]):
#     img=np.array(img_array[index,:,:],dtype=np.uint8)
#     img1=cv2.equalizeHist(img)
#     img_array[index,:,:]=copy.deepcopy(img1)

#S2 SIMPLEITK处理
binaryimg=sitk.BinaryThreshold(image,100,500,255,0)

#s3 OpenCV处理结果保存
#dcmimg= sitk.GetImageFromArray(img_array)
sitk.WriteImage(binaryimg,"equalizehist.mha")    

simpleitk函数参考:

ITK对应python中SimpleITK库的常用函数举例

官方文档

http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/

 类似资料: