Skip to content

Commit 17d56f6

Browse files
authored
Merge pull request #168 from rbrown333/fix_resample_add_normalisation
add_norm_fix_resampling_addtoOutput
2 parents 9836a54 + fe81532 commit 17d56f6

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

pydicer/analyse/data.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"interpolator": "sitkNearestNeighbor",
6363
"verbose": True,
6464
"removeOutliers": 10000,
65+
"normalizeImage": False,
66+
"normalizeScale": None,
6567
}
6668

6769

@@ -433,9 +435,6 @@ def compute_radiomics(
433435
interpolator = settings.get("interpolator")
434436
resample_pixel_spacing = settings.get("resampledPixelSpacing")
435437

436-
resample_pixel_spacing = list(image.GetSpacing())
437-
settings["resampledPixelSpacing"] = resample_pixel_spacing
438-
439438
if resample_to_image:
440439
resample_pixel_spacing = list(image.GetSpacing())
441440
settings["resampledPixelSpacing"] = resample_pixel_spacing
@@ -448,6 +447,18 @@ def compute_radiomics(
448447
logger.error("Error during resampling")
449448
continue
450449

450+
# Add normalisation of image after resampling
451+
normalize_image = settings.get("normalizeImage")
452+
normalize_scale = settings.get("normalizeScale")
453+
454+
if normalize_image is not False and normalize_scale is not None:
455+
try:
456+
image = imageoperations.normalizeImage(image, **settings)
457+
except ValueError as e:
458+
logger.exception(e)
459+
logger.error("Error during nomalisation")
460+
continue
461+
451462
df_contour = pd.DataFrame()
452463

453464
for rad in radiomics:
@@ -512,6 +523,21 @@ def compute_radiomics(
512523
if col_key not in meta_data_cols:
513524
meta_data_cols.append(col_key)
514525

526+
#add normalisation and resampling details
527+
output_frame.insert(
528+
loc=0, column="NormalisationScale", value=settings["normalizeScale"]
529+
)
530+
if settings["resampledPixelSpacing"] is not None:
531+
output_frame.insert(
532+
loc=0,column="ResampledPixelSpacing",
533+
value=settings["resampledPixelSpacing"][0]
534+
)
535+
else:
536+
output_frame.insert(
537+
loc=0, column="ResampledPixelSpacing",
538+
value=settings["resampledPixelSpacing"]
539+
)
540+
515541
output_frame.insert(loc=0, column="StructHashedUID", value=struct_row.hashed_uid)
516542
output_frame.insert(loc=0, column="ImageHashedUID", value=img_row.hashed_uid)
517543
output_frame.insert(loc=0, column="Patient", value=struct_row.patient_id)

0 commit comments

Comments
 (0)