Skip to content

Commit

Permalink
Merge f069364 into 0232234
Browse files Browse the repository at this point in the history
  • Loading branch information
randlet committed Mar 31, 2021
2 parents 0232234 + f069364 commit 891d340
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pylinac/ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def __init__(self, array: np.ndarray, angle: float, roi_radius: float, dist_from
@property
def cnr(self) -> float:
"""The contrast-to-noise value of the HU disk"""
if self.background_median is None or self.background_std is None:
return None
return 2*abs(self.pixel_value - self.background_median) / (self.std + self.background_std)

@property
Expand Down Expand Up @@ -248,8 +250,12 @@ def _setup_rois(self) -> None:
for name, setting in self.background_roi_settings.items():
self.background_rois[name] = HUDiskROI(self.image, setting['angle_corrected'], setting['radius_pixels'], setting['distance_pixels'],
self.phan_center)
background_median = np.mean([roi.pixel_value for roi in self.background_rois.values()])
background_std = np.std([roi.pixel_value for roi in self.background_rois.values()])
if self.background_rois:
background_median = np.mean([roi.pixel_value for roi in self.background_rois.values()])
background_std = np.std([roi.pixel_value for roi in self.background_rois.values()])
else:
background_median = None
background_std = None

for name, setting in self.roi_settings.items():
nominal_value = setting.get('value', 0)
Expand Down

0 comments on commit 891d340

Please sign in to comment.