Skip to content

Commit

Permalink
Make displaying DICOM verification image optional (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
niwilso committed Jan 5, 2023
1 parent b0430ca commit 1d07b03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def __init__(
def verify_dicom_instance(
self,
instance: pydicom.dataset.FileDataset,
padding_width: int = 25,
padding_width: Optional[int] = 25,
display_image: Optional[bool] = True,
**kwargs,
) -> Tuple[PIL.Image.Image, dict, list]:
) -> Tuple[Optional[PIL.Image.Image], dict, list]:
"""Verify PII on a single DICOM instance.
:param instance: Loaded DICOM instance including pixel data and metadata.
:param padding_width: Padding width to use when running OCR.
:param display_image: If the verificationimage is displayed and returned.
:param kwargs: Additional values for the analyze method in ImageAnalyzerEngine.
:return: DICOM instance with boxes identifying PHI, OCR results,
:return: Image with boxes identifying PHI, OCR results,
and analyzer results.
"""
instance_copy = deepcopy(instance)
Expand Down Expand Up @@ -80,8 +82,10 @@ def verify_dicom_instance(
)

# Get image with verification boxes
verify_image = self.verify(
image, ad_hoc_recognizers=[deny_list_recognizer], **kwargs
verify_image = (
self.verify(image, ad_hoc_recognizers=[deny_list_recognizer], **kwargs)
if display_image
else None
)

return verify_image, ocr_results, analyzer_results
Expand All @@ -90,22 +94,24 @@ def eval_dicom_instance(
self,
instance: pydicom.dataset.FileDataset,
ground_truth: dict,
padding_width: int = 25,
tolerance: int = 50,
padding_width: Optional[int] = 25,
tolerance: Optional[int] = 50,
display_image: Optional[bool] = False,
**kwargs,
) -> Tuple[PIL.Image.Image, dict]:
) -> Tuple[Optional[PIL.Image.Image], dict]:
"""Evaluate performance for a single DICOM instance.
:param instance: Loaded DICOM instance including pixel data and metadata.
:param ground_truth: Dictionary containing ground truth labels for the instance.
:param padding_width: Padding width to use when running OCR.
:param tolerance: Pixel distance tolerance for matching to ground truth.
:param display_image: If the verificationimage is displayed and returned.
:param kwargs: Additional values for the analyze method in ImageAnalyzerEngine.
:return: Evaluation comparing redactor engine results vs ground truth.
"""
# Verify detected PHI
verify_image, ocr_results, analyzer_results = self.verify_dicom_instance(
instance, padding_width, **kwargs
instance, padding_width, display_image, **kwargs
)
formatted_ocr_results = self._get_bboxes_from_ocr_results(ocr_results)
detected_phi = self._get_bboxes_from_analyzer_results(analyzer_results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_eval_dicom_correctly(

# Act
test_image, test_eval_results = mock_engine.eval_dicom_instance(
get_mock_dicom_instance, ground_truth, PADDING_WIDTH, tolerance
get_mock_dicom_instance, ground_truth, PADDING_WIDTH, tolerance, True
)

# Assert
Expand Down

0 comments on commit 1d07b03

Please sign in to comment.