|
6 | 6 | from nipype.interfaces.freesurfer import * |
7 | 7 | from .utils import copy_file, copy_files |
8 | 8 |
|
| 9 | + |
9 | 10 | def checkT1s(T1_files, cw256=False): |
10 | 11 | """Verifying size of inputs and setting workflow parameters""" |
11 | | - import SimpleITK as sitk |
12 | | - import os |
13 | 12 | import sys |
14 | | - # check that the files are in a list |
15 | | - if not type(T1_files) == list: |
16 | | - T1_files = [T1_files] |
| 13 | + import nibabel as nib |
| 14 | + from nipype.utils.filemanip import filename_to_list |
| 15 | + |
| 16 | + T1_files = filename_to_list(T1_files) |
17 | 17 | if len(T1_files) == 0: |
18 | 18 | print("ERROR: No T1's Given") |
19 | 19 | sys.exit(-1) |
20 | | - for i, t1 in enumerate(T1_files): |
21 | | - if t1.endswith(".mgz"): |
22 | | - # convert input fs files to NIFTI |
23 | | - convert = MRIConvert() |
24 | | - convert.inputs.in_file = t1 |
25 | | - convert.inputs.out_file = os.path.abspath(os.path.basename(t1).replace('.mgz', '.nii.gz')) |
26 | | - convert.run() |
27 | | - T1_files[i] = convert.inputs.out_file |
28 | | - size = None |
29 | | - origvol_names = list() |
30 | | - for i, t1 in enumerate(T1_files): |
31 | | - # assign an input number |
32 | | - file_num = str(i + 1) |
33 | | - while len(file_num) < 3: |
34 | | - file_num = '0' + file_num |
35 | | - origvol_names.append("{0}.mgz".format(file_num)) |
36 | | - # check the size of the image |
37 | | - img = sitk.ReadImage(t1) |
38 | | - if not size: |
39 | | - size = img.GetSize() |
40 | | - elif size != img.GetSize(): |
41 | | - print("ERROR: T1s not the same size. Cannot process {0} {1} together".format(T1_files[0], |
42 | | - otherFilename)) |
| 20 | + |
| 21 | + shape = nib.load(T1_files[0]).shape |
| 22 | + for t1 in T1_files[1:]: |
| 23 | + if nib.load(t1).shape != shape: |
| 24 | + print("ERROR: T1s not the same size. Cannot process {0} and {1} " |
| 25 | + "together".format(T1_files[0], t1)) |
43 | 26 | sys.exit(-1) |
| 27 | + |
| 28 | + origvol_names = ["{0:03d}.mgz".format(i + 1) for i in range(len(T1_files))] |
| 29 | + |
44 | 30 | # check if cw256 is set to crop the images if size is larger than 256 |
45 | | - if not cw256: |
46 | | - for dim in size: |
47 | | - if dim > 256: |
48 | | - print("Setting MRI Convert to crop images to 256 FOV") |
49 | | - cw256 = True |
50 | | - if len(T1_files) > 1: |
51 | | - resample_type = 'cubic' |
52 | | - else: |
53 | | - resample_type = 'interpolate' |
| 31 | + if not cw256 and any(dim > 256 for dim in shape): |
| 32 | + print("Setting MRI Convert to crop images to 256 FOV") |
| 33 | + cw256 = True |
| 34 | + |
| 35 | + resample_type = 'cubic' if len(T1_files) > 1 else 'interpolate' |
54 | 36 | return T1_files, cw256, resample_type, origvol_names |
55 | 37 |
|
| 38 | + |
56 | 39 | def create_AutoRecon1(name="AutoRecon1", longitudinal=False, field_strength='1.5T', |
57 | 40 | custom_atlas=None, plugin_args=None): |
58 | 41 | """Creates the AutoRecon1 workflow in nipype. |
|
0 commit comments