需要安装OpenCV和SimpleItk。
SimpleItk比较简单,直接pip install SimpleItk即可。
代码如下:
#coding:utf-8
import SimpleITK as sitk
import cv2
#LKDS-00058,-102.655469971,108.188810974,438.759994507,12.2279986879
if __name__ == '__main__':
filename = "F:/cancer_solution/data/train_subset00/LKDS-00058.mhd"
ds = sitk.ReadImage(filename)
img_array = sitk.GetArrayFromImage(ds)
frame_num, width, height = img_array.shape
outpath = "F:/cancer_solution/out/train/LKDS-00058"
index = -1
for img_item in img_array:
index = index + 1
cv2.imwrite("%s/%d.png"%(outpath,index),img_item)
print "done!"
目前还不太理解(x,y,z)坐标是如何对应的。
但祈世间人无病,何愁架上药生尘。癌症,终有一天可以被战胜。