Skip to content

Commit

Permalink
Merge pull request #168 from rbrown333/fix_resample_add_normalisation
Browse files Browse the repository at this point in the history
add_norm_fix_resampling_addtoOutput
  • Loading branch information
pchlap authored Sep 23, 2024
2 parents 9836a54 + fe81532 commit 17d56f6
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pydicer/analyse/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"interpolator": "sitkNearestNeighbor",
"verbose": True,
"removeOutliers": 10000,
"normalizeImage": False,
"normalizeScale": None,
}


Expand Down Expand Up @@ -433,9 +435,6 @@ def compute_radiomics(
interpolator = settings.get("interpolator")
resample_pixel_spacing = settings.get("resampledPixelSpacing")

resample_pixel_spacing = list(image.GetSpacing())
settings["resampledPixelSpacing"] = resample_pixel_spacing

if resample_to_image:
resample_pixel_spacing = list(image.GetSpacing())
settings["resampledPixelSpacing"] = resample_pixel_spacing
Expand All @@ -448,6 +447,18 @@ def compute_radiomics(
logger.error("Error during resampling")
continue

# Add normalisation of image after resampling
normalize_image = settings.get("normalizeImage")
normalize_scale = settings.get("normalizeScale")

if normalize_image is not False and normalize_scale is not None:
try:
image = imageoperations.normalizeImage(image, **settings)
except ValueError as e:
logger.exception(e)
logger.error("Error during nomalisation")
continue

df_contour = pd.DataFrame()

for rad in radiomics:
Expand Down Expand Up @@ -512,6 +523,21 @@ def compute_radiomics(
if col_key not in meta_data_cols:
meta_data_cols.append(col_key)

#add normalisation and resampling details
output_frame.insert(
loc=0, column="NormalisationScale", value=settings["normalizeScale"]
)
if settings["resampledPixelSpacing"] is not None:
output_frame.insert(
loc=0,column="ResampledPixelSpacing",
value=settings["resampledPixelSpacing"][0]
)
else:
output_frame.insert(
loc=0, column="ResampledPixelSpacing",
value=settings["resampledPixelSpacing"]
)

output_frame.insert(loc=0, column="StructHashedUID", value=struct_row.hashed_uid)
output_frame.insert(loc=0, column="ImageHashedUID", value=img_row.hashed_uid)
output_frame.insert(loc=0, column="Patient", value=struct_row.patient_id)
Expand Down

0 comments on commit 17d56f6

Please sign in to comment.