Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set background_median and background_std to None when no background ROI's present #355

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to mean per your own comment and all good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

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