我试图用 python3 和 pydicom 库读取 dicom 文件。对于某些dicom数据,当我尝试打印pydicom.dcmread的结果时,我无法正确获取数据并收到错误消息。但是,我尝试使用 python2 并且效果很好。查了元信息,和其他可以处理的dicom文件对比,没发现有什么区别。import pydiomds = pydicom.dcmread("xxxxx.dicom")print(ds)Traceback (most recent call last): File "generate_train_data.py", line 387, in <module> tf.app.run() File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "generate_train_data.py", line 371, in main create_ann() File "generate_train_data.py", line 368, in create_ann ds_ann_dir, case_name, merge_channel=False) File "generate_train_data.py", line 290, in process_dcm_set all_dcms, dcm_truth_infos = convert_dicoms(dcm_list, zs) File "generate_train_data.py", line 179, in convert_dicoms instance_num, pixel_spacing, img_np = extract_info(dcm_path) File "generate_train_data.py", line 147, in extract_info print(ds)UnicodeEncodeError: 'ascii' codec can't encode characters in position 2277-2279: ordinal not in range(128)任何人都遇到过同样的问题?
2 回答
守着星空守着你
TA贡献1799条经验 获得超8个赞
你能举一个这样的 dicom 文件的例子吗?使用 python 3.7运行 pydicom示例时,它运行良好:
import matplotlib.pyplot as plt
import pydicom
from pydicom.data import get_testdata_files
filename = get_testdata_files("CT_small.dcm")[0]
ds = pydicom.dcmread(filename)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
它还可以处理来自Medical Image Samples的示例 dicom 文件。
添加回答
举报
0/150
提交
取消