Skip to content

Commit

Permalink
added PD modality, added code to not normalize to [0,1500]
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik-code committed Sep 9, 2024
1 parent dfb9655 commit e7f1316
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions spineps/phase_pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def preprocess_input(
mri_nii: NII,
debug_data: dict, # noqa: ARG001
pad_size: int = 4,
proc_normalize_input: bool = True,
proc_do_n4_bias_correction: bool = True,
proc_crop_input: bool = True,
verbose: bool = False,
Expand All @@ -24,8 +25,15 @@ def preprocess_input(
# Crop Down
try:
# Enforce to range [0, 1500]
mri_nii.normalize_to_range_(min_value=0, max_value=9000, verbose=logger)
crop = mri_nii.compute_crop(dist=0) if proc_crop_input else (slice(None, None), slice(None, None), slice(None, None))
if proc_normalize_input:
mri_nii.normalize_to_range_(min_value=0, max_value=9000, verbose=logger)
crop = mri_nii.compute_crop(dist=0) if proc_crop_input else (slice(None, None), slice(None, None), slice(None, None))
else:
crop = (
mri_nii.compute_crop(minimum=mri_nii.min(), dist=0)
if proc_crop_input
else (slice(None, None), slice(None, None), slice(None, None))
)
except ValueError:
logger.print("Image Nifty is empty, skip this", Log_Type.FAIL)
return None, ErrCode.EMPTY
Expand All @@ -40,7 +48,8 @@ def preprocess_input(
logger.print(f"N4 Bias field correction done in {perf_counter() - n4_start} sec", verbose=True)

# Enforce to range [0, 1500]
cropped_nii.normalize_to_range_(min_value=0, max_value=1500, verbose=logger)
if proc_normalize_input:
cropped_nii.normalize_to_range_(min_value=0, max_value=1500, verbose=logger)

# Uncrop again
# uncropped_input[crop] = cropped_nii.get_array()
Expand Down
1 change: 1 addition & 0 deletions spineps/seg_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Modality(Enum_Compare):
CT = auto()
SEG = auto()
MPR = auto()
PD = auto()

@classmethod
def format_keys(cls, modalities: Self | list[Self]) -> list[str]:
Expand Down
2 changes: 2 additions & 0 deletions spineps/seg_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def process_img_nii( # noqa: C901
override_postpair: bool = False,
override_ctd: bool = False,
proc_pad_size: int = 4,
proc_normalize_input: bool = True,
# Processings
# Semantic
proc_sem_crop_input: bool = True,
Expand Down Expand Up @@ -385,6 +386,7 @@ def process_img_nii( # noqa: C901
pad_size=input_package.pad_size,
debug_data=debug_data_run,
proc_crop_input=proc_sem_crop_input,
proc_normalize_input=proc_normalize_input,
proc_do_n4_bias_correction=proc_sem_n4_bias_correction,
verbose=verbose,
)
Expand Down

0 comments on commit e7f1316

Please sign in to comment.