[英]The system cannot find the path specified:
Following is my code to read a dicom file, But I am having issue in reading the file, any help will be appreciated以下是我读取 dicom 文件的代码,但我在读取文件时遇到问题,任何帮助将不胜感激
<import cv2
import pydicom as dicom # for reading dicom files
import os # for doing directory operations
import pandas as pd # for some simple data
import matplotlib.pyplot as plt
import matplotlib.image as mpimage
import numpy as np
data_dir = r'D:\project\New folder\LungNoduleDetectionClassification-master'
patients = os.listdir(data_dir)
labels_df = pd.read_csv(r'D:\project\New folder\LungNoduleDetectionClassification-master\stage1_labels.csv', index_col=0)
labels_df.head()
import matplotlib.pyplot as plt
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]))
plt.imshow(slices[0].pixel_array)
plt.show()>
Error :-
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-39-0cdfa4febaf1> in <module>
3 for patient in patients[:1]:
4 path = data_dir + patient
----> 5 slices = [dicom.read_file(path + '/' + s) for s in os.listdir(path)]
6 slices.sort(key = lambda x: int(x.ImagePositionPatient[2]))
7
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\project\\New folder\\LungNoduleDetectionClassification-master1-001.dcm'
Your combination of directory name and filename is problematic:您的目录名和文件名的组合有问题:
data_dir = r'D:\project\New folder\LungNoduleDetectionClassification-master'
patients = os.listdir(data_dir)
...
for patient in patients[:1]:
path = data_dir + patient
This will mean path
contains the directory name and the filename without a directory separator to separate them.这意味着path
包含目录名和文件名,没有目录分隔符来分隔它们。
Generally, you want to do something like this to ensure the two are combined correctly:通常,您希望执行以下操作以确保正确组合两者:
path = os.path.join(data_dir, patient)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.