|
13 | 13 | from rbc.core.niwrap import generate_exec_folder |
14 | 14 |
|
15 | 15 |
|
16 | | -def resample_template_to_bold_grid(bold_ref: Path, template: Path) -> Path: |
| 16 | +def resample_img_to_bold_grid(bold_ref: Path, img: Path) -> Path: |
17 | 17 | """Resample template to BOLD grid if shapes differ. |
18 | 18 |
|
19 | 19 | Args: |
20 | 20 | bold_ref: BOLD reference volume (used for ITK conversion). |
21 | | - template: Brain template in target space. |
| 21 | + img: 3D image in target space to resample. |
22 | 22 |
|
23 | 23 | Returns: |
24 | | - Resampled template image with BOLD grid |
| 24 | + Resampled 3D image with BOLD grid |
25 | 25 |
|
26 | 26 | Raises: |
27 | 27 | FileNotFoundError: No motion .mat files found in the directory. |
28 | 28 | ValueError: Number of motion matrices does not match STC volumes. |
29 | 29 | """ |
30 | 30 | bold_ref_img = nib.nifti1.load(bold_ref) |
31 | | - template_img = nib.nifti1.load(template) |
| 31 | + img_obj = nib.nifti1.load(img) |
32 | 32 |
|
33 | 33 | # If 4D, extract first volume |
34 | 34 | if len(bold_ref_img.shape) > 3: |
35 | 35 | bold_ref_img = nib.four_to_three(bold_ref_img)[0] |
36 | 36 | # If same shape, no need to resample |
37 | | - if bold_ref_img.shape == template_img.shape: |
38 | | - return template_img |
| 37 | + if bold_ref_img.shape == img_obj.shape: |
| 38 | + return img |
39 | 39 |
|
40 | | - template_img = resample_from_to(template_img, bold_ref_img) |
41 | | - template_img_path = ( |
42 | | - generate_exec_folder("template_resample_to_bold_grid") |
43 | | - / "template_resampled.nii.gz" |
| 40 | + img_resampled = resample_from_to(img_obj, bold_ref_img) |
| 41 | + img_resampled_path = ( |
| 42 | + generate_exec_folder("img_resample_to_bold_grid") / "resampled.nii.gz" |
44 | 43 | ) |
45 | | - nib.save(template_img, template_img_path) |
46 | | - return template_img_path |
| 44 | + nib.save(img_resampled, img_resampled_path) |
| 45 | + return img_resampled_path |
0 commit comments