找不到 .nii 文件

can't find .nii files

我正在尝试使用 nibabel 库加载 .nii 文件,但 运行 出现以下 .nii 文件错误:

>>> path = '..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\ADNI_002_S_0938_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070219175406282_S19852_I40980.nii'

>>> with open(Path(path), 'rb') as f:
>>>    print('great success!')
FileNotFoundError: [Errno 2] No such file or directory: '..\..\data\raw\data\images\AD\female\005_S_1341\MPR__GradWarp__B1_Correction__N3__Scaled\2007-03-07_12_44_49.0\S27673\ADNI_005_S_1341_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070717180348670_S27673_I60417.nii'

以及测试文件:

>>> path =  '..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\test.txt'

>>> with open(Path(path), 'rb') as f:
>>>    print('great success!') 
great success!

或者,设计用于读取 .nii 文件的库仍然存在问题:

>>> import nibabel as nib
>>> path = '..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\ADNI_002_S_0938_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070219175406282_S19852_I40980.nii'

>>> nib.load(path)
FileNotFoundError: No such file or no access: '..\..\data\raw\data\images\AD\female[=12=]5_S_1341\MPR__GradWarp__B1_Correction__N3__Scaled07-03-07_12_44_49.0\S27673\ADNI_005_S_1341_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070717180348670_S27673_I60417.nii'

以及测试文件:

>>> path = '..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\test.txt'

>>> nib.load(path)
ImageFileError: Empty file: '..\..\data\raw\data\images\AD\female[=13=]2_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled06-10-05_15_54_26.0\S19852\test.txt'

我认为这是奇怪的行为,因为库找到了文本文件,但没有找到存在于同一目录中的 .nii 文件。

注:

更新:

当前文件结构:

完整追溯:

由于 os.listdir('..\..\data\raw\data\images\AD\female\002_S_0938\MPR__GradWarp__B1_Correction__N3__Scaled\2006-10-05_15_54_26.0\S19852\') returns 两个文件,您可以打开文件 test.txt 但不能 'ADNI_002_S_0938_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070219175406282_S19852_I40980.nii',这表明问题可能与文件路径过长有关。

可以通过将此注册表项设置为 1 来禁用 260 个字符的限制:Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled

Enable Long Paths in Windows 10, Version 1607, and Later