Skip to content

Commit dfb4bc0

Browse files
committed
Corrections typos
1 parent ae997e3 commit dfb4bc0

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

NIfTI-Guide.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ To resample a CTA image, we use `sitk.Resample()`, ensuring that the other dimen
10311031
10321032
10331033
```python
1034-
def resample_cta_pipeline(image: sitk.Image, new_z_size=512):
1034+
def resample_pipeline(image: sitk.Image, new_z_size=512):
10351035
"""
10361036
Resamples a CTA scan to have a uniform number of slices along Z while keeping X-Y unchanged.
10371037
@@ -1074,7 +1074,7 @@ def resample_cta_pipeline(image: sitk.Image, new_z_size=512):
10741074
10751075
# Example usage
10761076
image = sitk.ReadImage("toy-CTA.nii.gz")
1077-
resampled_image = resample_cta(image)
1077+
resampled_image = resample_pipeline(image)
10781078
sitk.WriteImage(resampled_image, "toy-CTA-resampled.nii.gz")
10791079
```
10801080
@@ -1154,10 +1154,10 @@ resample_template(input_template_path, output_template_path, desired_size)
11541154
11551155
The pipeline works as follows:
11561156
1157-
- **1️. Preprocessing the CTA Image**: Load the CTA scan and apply Gaussian filtering preprocessing and clip intensity values (0-95 intensity range)
1158-
- **2️. Loading the Images & Masks**: Load the CTA, CTA mask, MNI template, and MNI template mask. Ensure the CTA and MNI template share the same pixel type. Clip CTA intensities between 0 and 100.
1159-
- **3️. Performing the Registration**: Use Mattes Mutual Information as the metric. Initialize the transformation based on image moments. Optimize using Gradient Descent. Execute registration.
1160-
- **4️. Applying the Transformation**: Resample the CTA to align with the MNI template. Save the registered CTA and transformation matrix (`.tfm`).
1157+
- **1. Preprocessing the CTA Image**: Load the CTA scan and apply Gaussian filtering preprocessing and clip intensity values (0-95 intensity range)
1158+
- **2. Loading the Images & Masks**: Load the CTA, CTA mask, MNI template, and MNI template mask. Ensure the CTA and MNI template share the same pixel type. Clip CTA intensities between 0 and 100.
1159+
- **3. Performing the Registration**: Use Mattes Mutual Information as the metric. Initialize the transformation based on image moments. Optimize using Gradient Descent. Execute registration.
1160+
- **4. Applying the Transformation**: Resample the CTA to align with the MNI template. Save the registered CTA and transformation matrix (`.tfm`).
11611161
11621162
<br>
11631163
@@ -1185,24 +1185,29 @@ import nibabel as nib
11851185
from scipy.ndimage import gaussian_filter
11861186
import os
11871187
1188-
def register_cta_pipeline(
1189-
cta_image_nib, brain_mask_nib, template_nib, template_mask_nib, output_dir, pat="001"
1190-
):
1188+
def register_pipeline(
1189+
cta_image_path, brain_mask_path, template_path, template_mask_path, output_dir, filename):
11911190
"""
11921191
Pipeline for registering CTA images to an MNI template while preserving 512x512 dimensions.
11931192
11941193
Parameters:
1195-
- cta_image_nib (nibabel.Nifti1Image): The input CTA image loaded with nibabel.
1196-
- brain_mask_nib (nibabel.Nifti1Image): The corresponding brain mask loaded with nibabel.
1197-
- template_nib (nibabel.Nifti1Image): The MNI template loaded with nibabel.
1198-
- template_mask_nib (nibabel.Nifti1Image): The MNI brain mask loaded with nibabel.
1194+
- cta_image_path (str): The input CTA image path.
1195+
- brain_mask_path (str): The corresponding brain mask path.
1196+
- template_path (str): The MNI template path.
1197+
- template_mask_path (str): The MNI brain mask path.
11991198
- output_dir (str): Directory to save the registered images and transformations.
12001199
- filename (str): Patient ID or identifier for file naming.
12011200
12021201
Outputs:
12031202
- Saves registered CTA images and the transformation matrix in the output directory.
12041203
"""
12051204
1205+
# Load images with nibabel
1206+
cta_image_nib = nib.load(cta_image_path)
1207+
brain_mask_nib = nib.load(brain_mask_path)
1208+
template_nib = nib.load(template_path)
1209+
template_mask_nib = nib.load(template_mask_path)
1210+
12061211
# Define output file paths
12071212
transformation_path = os.path.join(output_dir, f"{filename}_transformation_cta_clipped_to_mni_template.tfm")
12081213
registered_cta_path = os.path.join(output_dir, f"{filename}_cta_registered_to_mni.nii.gz")
@@ -1298,18 +1303,12 @@ template_path = "coreTemplate-MNI152lin_T1_1mm.nii.gz"
12981303
template_mask_path = "coreTemplate-MNI152lin_T1_1mm-mask.nii.gz"
12991304
output_dir = "registered_output"
13001305
1301-
# Load images with nibabel
1302-
cta_image_nib = nib.load(cta_image_path)
1303-
brain_mask_nib = nib.load(brain_mask_path)
1304-
template_nib = nib.load(template_path)
1305-
template_mask_nib = nib.load(template_mask_path)
1306-
13071306
# Import the function
1308-
register_cta_pipeline(
1309-
cta_image_nib=cta_image_nib,
1310-
brain_mask_nib=brain_mask_nib,
1311-
template_nib=template_nib,
1312-
template_mask_nib=template_mask_nib,
1307+
register_pipeline(
1308+
cta_image_path=cta_image_path,
1309+
brain_mask_path=brain_mask_path,
1310+
template_path=template_path,
1311+
template_mask_path=template_mask_path,
13131312
output_dir=output_dir,
13141313
filename="toy-CTA"
13151314
)

0 commit comments

Comments
 (0)