Skip to content

Commit

Permalink
Merge pull request #345 from jrkerns/PYL-339_Add_SSD_parameter_to_pla…
Browse files Browse the repository at this point in the history
…nar_imaging

Closes #339
  • Loading branch information
jrkerns committed Mar 11, 2021
2 parents 5de983d + 1c681b5 commit 0232234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pylinac/planar_imaging.py
Expand Up @@ -90,6 +90,7 @@ def __init__(self, filepath: str):
self._center_override = None
self._high_contrast_threshold = None
self._low_contrast_threshold = None
self._ssd: float = 100
self.mtf = None

@classmethod
Expand All @@ -116,7 +117,7 @@ def _check_inversion(self):
pass

def analyze(self, low_contrast_threshold: float=0.05, high_contrast_threshold: float=0.5, invert: bool=False, angle_override: Optional[float]=None,
center_override: Optional[tuple]=None, size_override: Optional[float]=None) -> None:
center_override: Optional[tuple]=None, size_override: Optional[float]=None, ssd: float = 100) -> None:
"""Analyze the phantom using the provided thresholds and settings.
Parameters
Expand Down Expand Up @@ -147,12 +148,15 @@ def analyze(self, low_contrast_threshold: float=0.05, high_contrast_threshold: f
.. Note::
This value is not necessarily the physical size of the phantom. It is an arbitrary value.
ssd
The SSD of the phantom itself in cm.
"""
self._angle_override = angle_override
self._center_override = center_override
self._size_override = size_override
self._high_contrast_threshold = high_contrast_threshold
self._low_contrast_threshold = low_contrast_threshold
self._ssd = ssd
self._check_inversion()
if invert:
self.image.invert()
Expand Down Expand Up @@ -587,10 +591,9 @@ def phantom_ski_region(self) -> RegionProperties:
for phantom_idx, region in enumerate(regions):
if region.bbox_area < 1000:
continue
is_at_iso = np.isclose(region.bbox_area, phantom_size_pix, rtol=0.07)
is_at_140cm = np.isclose(region.bbox_area, phantom_size_pix/(1.4**2), rtol=0.07)
is_at_ssd = np.isclose(region.bbox_area, phantom_size_pix/(self._ssd/100)**2, rtol=0.1)
centered = np.allclose(region.centroid, img_center, rtol=0.1)
if (is_at_iso or is_at_140cm) and centered:
if is_at_ssd and centered:
blobs.append(phantom_idx)

if not blobs:
Expand Down
4 changes: 4 additions & 0 deletions tests_basic/test_planar_imaging.py
Expand Up @@ -111,6 +111,10 @@ class SIQC3_2(PlanarPhantomMixin, TestCase):
file_path = ['QC3 2.5MV 2.dcm']
mtf_50 = 0.68

def test_wrong_ssd_fails(self):
with self.assertRaises(ValueError):
self.instance.analyze(ssd=140)


class LasVegasTestMixin(PlanarPhantomMixin):
klass = LasVegas
Expand Down

0 comments on commit 0232234

Please sign in to comment.