0

I am trying to load a file from the following path:

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

However, the file is not loading. If I move the file 1 level up and change the path to

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/S16309/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

it loads.

The only difference is the S13893 folder.

I have the following code:

import nibabel as nib
import matplotlib.pyplot as plt
from scipy.misc import imsave as imsave

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

im = nib.load(path).get_data()
print(im.shape)

any help would be great.

amankedia
  • 377
  • 2
  • 8
  • 23
  • u mean S16309 folder.. – Narendra Mar 02 '18 at 04:59
  • 1
    In the original version of this question, you had backslashes instead of forward slashes in the non-working path - is that how it was in your actual code? If so, the `\t` was being interpreted as a tab, and `\002` as an octal character escape. You either need to use raw string constants for Windows paths, double the backslashes to escape them, or use forward slashes (but this doesn't work for anything that will be executed via the command line). – jasonharper Mar 02 '18 at 05:02
  • I'd to point out that `from scipy.misc import imsave as imsave` can be written as just `from scipy.misc import imsave` – Mike Peder Mar 02 '18 at 06:29

2 Answers2

1

I tried using r in the beginning of the path, however it didn't work.

Also, I tried using \\?\ which again didn't work.

As a final resort, I found out that it was actually an issue with the path length and shortened the path by removing commonalities in the path for all files and it worked fine.

Thanks for all the help.

However, this is just a workaround I performed and the suggested edits/changes didn't work for me.

amankedia
  • 377
  • 2
  • 8
  • 23
0

In Windows you should try with:

path = r'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Narendra
  • 1,511
  • 1
  • 10
  • 20