【1】代码
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : 03test.py
@Time : 2021/05/21 10:50:10
@Author : Jian Song
@Contact : 1248975661@qq.com
@Desc : None
'''
# here put the import lib
#!/usr/bin/env python
from __future__ import print_function
import SimpleITK as sitk
import sys
import os
if len(sys.argv) < 3:
print("Usage: DicomSeriesReader <input_directory> <output_file>")
sys.exit(1)
print("Reading Dicom directory:", sys.argv[1])
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(sys.argv[1])
reader.SetFileNames(dicom_names)
image = reader.Execute()
size = image.GetSize()
print("Image size:", size[0], size[1], size[2])
print("Writing image:", sys.argv[2])
sitk.WriteImage(image, sys.argv[2])
if ("SITK_NOSHOW" not in os.environ):
sitk.Show(image, "Dicom Series")
'''
终端参数输入方法
(调用编辑器、文件名、参数1、参数2、参数3(中间空格分开))
python36 03test.py F:\PytorchTest\Simpleitk\03test\series-000001 F:\PytorchTest\Simpleitk\03test\outputfile\result.dcm
'''
【2】操作
vscode+python36+w7
打开终端输入(注意中间有空格)
python36 03test.py F:\PytorchTest\Simpleitk\03test\series-000001 F:\PytorchTest\Simpleitk\03test\outputfile\result.mha
python36:编辑器(本人改了名字,将python改为python36)
03test.py:文件名
F:\PytorchTest\Simpleitk\03test\series-000001:读入文件夹
F:\PytorchTest\Simpleitk\03test\outputfile\result.mha:输出文件夹以及文件名,此处设置为mha文件