Skip to content

Commit 437f5a6

Browse files
committed
added kernel check to aortic_calcium
1 parent 630971a commit 437f5a6

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

comp2comp/aortic_calcium/aortic_calcium.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib.pyplot as plt
1414
import numpy as np
1515
from scipy import ndimage
16+
import pydicom
1617

1718
# from totalsegmentator.libs import (
1819
# download_pretrained_weights,
@@ -32,6 +33,10 @@ def __init__(self):
3233
# self.input_path = input_path
3334

3435
def __call__(self, inference_pipeline):
36+
# check if kernels are allowed if agatson is used
37+
if inference_pipeline.args.threshold == 'agatson':
38+
self.reconKernelChecker(inference_pipeline.dcm)
39+
3540
# inference_pipeline.dicom_series_path = self.input_path
3641
self.output_dir = inference_pipeline.output_dir
3742
self.output_dir_segmentations = os.path.join(self.output_dir, "segmentations/")
@@ -114,6 +119,31 @@ def aorta_seg(
114119

115120
return seg
116121

122+
def reconKernelChecker(self, dcm):
123+
ge_kernels = ["standard", "md stnd"]
124+
philips_kernels = ["a", "b", "c", "sa", "sb"]
125+
canon_kernels = ["fc08", "fc18"]
126+
siemens_kernels = ["b20s", "b20f", "b30f", "b31s", "b31f", "br34f", "b35f", "bf37f", "br38f", "b41f",
127+
"qr40", "qr40d", "br36f", "br40", "b40f", "br40d", "i30f", "i31f", "i26f", "i31s",
128+
"i40f", "b30s", "br36d", "bf39f", "b41s", "br40f"]
129+
toshiba_kernels = ["fc01", "fc02", "fc07", "fc08", "fc13", "fc18"]
130+
131+
all_kernels = ge_kernels+philips_kernels+canon_kernels+siemens_kernels+toshiba_kernels
132+
133+
conv_kernel_raw = dcm['ConvolutionKernel'].value
134+
135+
if isinstance(conv_kernel_raw, pydicom.multival.MultiValue):
136+
conv_kernel = conv_kernel_raw[0].lower()
137+
recon_kernel_extra = str(conv_kernel_raw)
138+
else:
139+
conv_kernel = conv_kernel_raw.lower()
140+
recon_kernel_extra = 'n/a'
141+
142+
if conv_kernel in all_kernels:
143+
return True
144+
else:
145+
raise ValueError('Reconstruction kernel not allowed, found: ' + conv_kernel +'\n'
146+
+ 'Allowed kernels are: ' + str(all_kernels))
117147

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

124154
def __call__(self, inference_pipeline):
155+
125156
# Set output dirs
126157
self.output_dir = inference_pipeline.output_dir
127158
self.output_dir_images_organs = os.path.join(self.output_dir, "images/")
@@ -567,7 +598,7 @@ def getSmallestArraySlice(self, input_mask, margin=0):
567598
)
568599

569600
return (slice(x_start, x_end), slice(y_start, y_end), slice(z_start, z_end))
570-
601+
571602

572603
class AorticCalciumMetrics(InferenceClass):
573604
"""Calculate metrics for the aortic calcifications"""

comp2comp/io/io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def __init__(self, input_path: Union[str, Path], pipeline_name=None, save=True):
8080
self.pipeline_name = pipeline_name
8181

8282
def __call__(self, inference_pipeline):
83+
dcm_files = [d for d in os.listdir(self.input_path) if d.endswith('.dcm')]
84+
inference_pipeline.dcm = pydicom.read_file(os.path.join(self.input_path, dcm_files[0]))
8385
if os.path.exists(
8486
os.path.join(
8587
inference_pipeline.output_dir, "segmentations", "converted_dcm.nii.gz"

comp2comp/utils/process.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def process_3d(args, pipeline_builder):
7676

7777
if path.endswith(".nii") or path.endswith(".nii.gz"):
7878
print("Processing: ", path)
79-
8079
else:
8180
print("Processing: ", path, " with ", num, " slices")
8281
min_slices = 30

0 commit comments

Comments
 (0)