Skip to content

Commit 2350a5a

Browse files
committed
add test and update documentaiton
1 parent 07c61b6 commit 2350a5a

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎TPTBox/stitching/README.md‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ You can verify alignment by opening the images in ITKSnap with "open additional
88

99
| Function | Description |
1010
|---|---|
11-
| `stitching(nii_list, out, ...)` | Stitch a list of `NII` objects; returns `(result_nii, ramp_nii)` |
12-
| `stitching_raw(paths, out, ...)` | Stitch from file paths directly |
11+
| `stitching(inputs, out, ...)` | High-level wrapper. `inputs` accepts any mix of `BIDS_FILE`, `NII`, `str`, or `Path`. Resolves the output path from a `BIDS_FILE` when one is passed. Returns `(result_nii, ramp_nii)` as `NII` objects. |
12+
| `stitching_raw(images, out, ...)` | Low-level driver. `images` accepts file paths, pre-loaded `NII` objects, or (fallback) `Nifti1Image` objects. Returns `(result_nii, ramp_nii)` as `NII` objects. |
1313
| `NAKO_stitch_T2w(HWS, BWS, LWS, n4_after_stitch=False)` | Stitch the three NAKO sagittal T2w spine stations (HWS cervical, BWS thoracic, LWS lumbar) into one volume |
1414

1515
![Example of a stitching](https://raw.githubusercontent.com/Hendrik-code/TPTBox/main/TPTBox/stitching/stitching.jpg "Example of a stitching")
@@ -24,7 +24,7 @@ stitching.py
2424
[-i IMAGES [IMAGES ...]] a list of input image paths
2525
[-o OUTPUT] The output image path
2626
[-v] verbose - if set, there will be more printouts.
27-
[-min_value MIN_VALUE] New pixels not present will get this value. Recommended 0 for MRI and for CT -1024 or the known min-value.
27+
[-min_value MIN_VALUE] Background fill used when resampling each chunk, and — when set explicitly — a hard floor applied to the stitched output. Pass 0 for MRI magnitude, -1024 for CT. Omitting it (the Python-API default `None`) uses 0 as the internal background and only applies a hard floor when the output dtype cannot represent negatives (unsigned integer types) — signed / float outputs then keep legitimate negatives (Philips-scaled fat-fraction, phase, B0 offsets).
2828
[-seg] This flag is required if you merge segmentation Niftis.
2929
Switches:
3030
[-no_bias] If set: Do not use n4_bias_field_correction. It speeds up the process, but n4_bias_field_correction helps in roughly aligning the histogram.
@@ -67,14 +67,15 @@ list_of_files = [
6767
# Call the stitching function
6868
# This will combine your images into a single NIfTI file
6969
stitching(
70-
list_of_files, # List of input files
71-
out="out_path_stitched_image.nii.gz", # Path to save stitched output
72-
is_seg=False, # Set True if these are segmentation masks
73-
is_ct=False, # True for CT, min_value will by -1024 instead of 0
70+
list_of_files, # BIDS_FILE / NII / str / Path (any mix)
71+
out="out_path_stitched_image.nii.gz", # Path or BIDS_FILE for the stitched output
72+
is_seg=False, # Set True for segmentation masks (forces integer dtype, nearest-neighbour resample)
73+
is_ct=False, # Sets min_value to -1024 (CT air) when min_value is not passed explicitly
7474
kick_out_fully_integrated_images=True,
75-
dtype=float, # Data type of the output image
75+
dtype=float, # Output dtype; "auto" picks the smallest lossless type from the inputs (float32 when any input has a non-trivial scl_slope/inter)
7676
match_histogram=False, # Match intensity histograms across images
7777
store_ramp=False, # Store blending ramp (optional)
78+
min_value=None, # Explicit background/floor. None (default) = clip only when the output dtype is unsigned integer (protects against negative-to-huge wraparound) and let signed / float outputs keep legitimate negatives. Pass 0 to floor magnitude MR at 0 so cubic-spline resample ringing doesn't leak small negatives into what should be a non-negative volume; pass -1024 for CT.
7879
)
7980
```
8081

‎unit_tests/test_stiching.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_stitching(
120120
self.assertTrue(output.exists(), output)
121121
output.unlink(missing_ok=True)
122122
# Assertions
123-
self.assertIsInstance(result, nib.Nifti1Image) # Check if result is a Nifti1Image instance
123+
self.assertIsInstance(result, NII) # Check the result is a NII (post-migration return type)
124124
# Add more assertions based on your requirements
125125

126126
def test_stitching2(self):

0 commit comments

Comments
 (0)