Skip to content

Commit

Permalink
added kernel check to aortic_calcium
Browse files Browse the repository at this point in the history
  • Loading branch information
malteekj committed Jul 11, 2024
1 parent 630971a commit 437f5a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion comp2comp/aortic_calcium/aortic_calcium.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage
import pydicom

# from totalsegmentator.libs import (
# download_pretrained_weights,
Expand All @@ -32,6 +33,10 @@ def __init__(self):
# self.input_path = input_path

def __call__(self, inference_pipeline):
# check if kernels are allowed if agatson is used
if inference_pipeline.args.threshold == 'agatson':
self.reconKernelChecker(inference_pipeline.dcm)

# inference_pipeline.dicom_series_path = self.input_path
self.output_dir = inference_pipeline.output_dir
self.output_dir_segmentations = os.path.join(self.output_dir, "segmentations/")
Expand Down Expand Up @@ -114,6 +119,31 @@ def aorta_seg(

return seg

def reconKernelChecker(self, dcm):
ge_kernels = ["standard", "md stnd"]
philips_kernels = ["a", "b", "c", "sa", "sb"]
canon_kernels = ["fc08", "fc18"]
siemens_kernels = ["b20s", "b20f", "b30f", "b31s", "b31f", "br34f", "b35f", "bf37f", "br38f", "b41f",
"qr40", "qr40d", "br36f", "br40", "b40f", "br40d", "i30f", "i31f", "i26f", "i31s",
"i40f", "b30s", "br36d", "bf39f", "b41s", "br40f"]
toshiba_kernels = ["fc01", "fc02", "fc07", "fc08", "fc13", "fc18"]

all_kernels = ge_kernels+philips_kernels+canon_kernels+siemens_kernels+toshiba_kernels

conv_kernel_raw = dcm['ConvolutionKernel'].value

if isinstance(conv_kernel_raw, pydicom.multival.MultiValue):
conv_kernel = conv_kernel_raw[0].lower()
recon_kernel_extra = str(conv_kernel_raw)
else:
conv_kernel = conv_kernel_raw.lower()
recon_kernel_extra = 'n/a'

if conv_kernel in all_kernels:
return True
else:
raise ValueError('Reconstruction kernel not allowed, found: ' + conv_kernel +'\n'
+ 'Allowed kernels are: ' + str(all_kernels))

class AorticCalciumSegmentation(InferenceClass):
"""Segmentaiton of aortic calcium"""
Expand All @@ -122,6 +152,7 @@ def __init__(self):
super().__init__()

def __call__(self, inference_pipeline):

# Set output dirs
self.output_dir = inference_pipeline.output_dir
self.output_dir_images_organs = os.path.join(self.output_dir, "images/")
Expand Down Expand Up @@ -567,7 +598,7 @@ def getSmallestArraySlice(self, input_mask, margin=0):
)

return (slice(x_start, x_end), slice(y_start, y_end), slice(z_start, z_end))


class AorticCalciumMetrics(InferenceClass):
"""Calculate metrics for the aortic calcifications"""
Expand Down
2 changes: 2 additions & 0 deletions comp2comp/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def __init__(self, input_path: Union[str, Path], pipeline_name=None, save=True):
self.pipeline_name = pipeline_name

def __call__(self, inference_pipeline):
dcm_files = [d for d in os.listdir(self.input_path) if d.endswith('.dcm')]
inference_pipeline.dcm = pydicom.read_file(os.path.join(self.input_path, dcm_files[0]))
if os.path.exists(
os.path.join(
inference_pipeline.output_dir, "segmentations", "converted_dcm.nii.gz"
Expand Down
1 change: 0 additions & 1 deletion comp2comp/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def process_3d(args, pipeline_builder):

if path.endswith(".nii") or path.endswith(".nii.gz"):
print("Processing: ", path)

else:
print("Processing: ", path, " with ", num, " slices")
min_slices = 30
Expand Down

0 comments on commit 437f5a6

Please sign in to comment.