我正在打开样本dicom文件,但出现此错误 [WinError 267]目录名称无效
我正在使用pydicom 1.1.0的anaconda,如果有人可以帮助我,甚至只是帮助我如何一般地加载DICOM文件,我将不胜感激。
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import pydicom
import os
import scipy.ndimage
import matplotlib.pyplot as plt
from skimage import measure, morphology
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
# Some constants
data_dir ="F:\\deep\\sample\\"
patients = os.listdir(data_dir)
for patient in patients[:1]:
path = data_dir + patient
slices = [dicom.read_file(path + '/' + s) for s in os.listdir(path)]
slices.sort(key = lambda x: int(x.ImagePositionPatient[2]))
#the first slice
plt.imshow(slices[0].pixel_array)
plt.show()
答案 0 :(得分:0)
反斜杠(\
)字符用于在其后转义该字符。如果您想在路径中使用实际的\
,则必须通过将其加倍(即\\
)来逃避它:
data_dir ="F:\\deep\\sample\\"
# Here -------^-----^