我正在尝试按顺序导入 3D 图像并将识别标签链接到每个文件夹。目前我有代码可以为 dicom 文件执行此操作,但我也在尝试使用 .tiff 图像文件:
data_dir = "\\tiff\\"
patients = os.listdir(data_dir)
labels_df = pd.read_csv('\\tiff_labels.csv', index_col = 0)
IMG_PX_SIZE = 50
HM_SLICES = 20
def process_data(patient, labels_df, image_px_size = 50, hm_slices = 20, visualize = False):
label = labels_df.at[patient, 'label']
path = data_dir + patient
slices = [pydicom.read_file(path + '/' + s, force = True) for s in os.listdir(path)]
slices.sort(key = lambda x: int(x.ImagePositionPatient[2]))
我尝试将第 9 行和第 10 行更改为:
slices = [cv2.imread(path + '/' + s) for s in os.listdir(path)]
slices.sort()
我发现的问题在第 10 行:key = lambda x: int(x.ImagePositionPatient[2])。ImagePositionPatient 是 dicoms 独有的东西,无法找到用另一种方式对图像进行排序的方法。
我收到错误:
Traceback (most recent call last):
File "preprocessing_data.py", line 83, in <module>
image_data, label = process_data(patient, labels_df, image_px_size = IMG_PX_SIZE, hm_slices = HM_SLICES)
File "preprocessing_data.py", line 28, in process_data
slices.sort()
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
蝴蝶不菲
冉冉说
相关分类