【7】SimpleITK输入终端参数将dicom转换为mha文件

【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文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值