@@ -49,15 +49,21 @@ def verify_dicom_instance(
4949 instance : pydicom .dataset .FileDataset ,
5050 padding_width : int = 25 ,
5151 display_image : bool = True ,
52+ use_metadata : bool = True ,
5253 ocr_kwargs : Optional [dict ] = None ,
54+ ad_hoc_recognizers : Optional [List [PatternRecognizer ]] = None ,
5355 ** text_analyzer_kwargs ,
5456 ) -> Tuple [Optional [PIL .Image .Image ], dict , list ]:
5557 """Verify PII on a single DICOM instance.
5658
5759 :param instance: Loaded DICOM instance including pixel data and metadata.
5860 :param padding_width: Padding width to use when running OCR.
5961 :param display_image: If the verificationimage is displayed and returned.
62+ :param use_metadata: Whether to redact text in the image that
63+ are present in the metadata.
6064 :param ocr_kwargs: Additional params for OCR methods.
65+ :param ad_hoc_recognizers: List of PatternRecognizer objects to use
66+ for ad-hoc recognizer.
6167 :param text_analyzer_kwargs: Additional values for the analyze method
6268 in ImageAnalyzerEngine.
6369
@@ -82,24 +88,17 @@ def verify_dicom_instance(
8288 loaded_image = Image .open (png_filepath )
8389 image = self ._add_padding (loaded_image , is_greyscale , padding_width )
8490
85- # Create custom recognizer using DICOM metadata
86- original_metadata , is_name , is_patient = self ._get_text_metadata (instance_copy )
87- phi_list = self ._make_phi_list (original_metadata , is_name , is_patient )
88- deny_list_recognizer = PatternRecognizer (
89- supported_entity = "PERSON" , deny_list = phi_list
90- )
91+ # Get analyzer results
9192 ocr_results = self .ocr_engine .perform_ocr (image )
92- analyzer_results = self .image_analyzer_engine .analyze (
93- image ,
94- ocr_kwargs = ocr_kwargs ,
95- ad_hoc_recognizers = [deny_list_recognizer ],
96- ** text_analyzer_kwargs ,
93+ analyzer_results = self ._get_analyzer_results (
94+ image , instance , use_metadata , ocr_kwargs , ad_hoc_recognizers ,
95+ ** text_analyzer_kwargs
9796 )
9897
9998 # Get image with verification boxes
10099 verify_image = (
101100 self .verify (
102- image , ad_hoc_recognizers = [ deny_list_recognizer ] , ** text_analyzer_kwargs
101+ image , ad_hoc_recognizers = ad_hoc_recognizers , ** text_analyzer_kwargs
103102 )
104103 if display_image
105104 else None
@@ -114,7 +113,9 @@ def eval_dicom_instance(
114113 padding_width : int = 25 ,
115114 tolerance : int = 50 ,
116115 display_image : bool = False ,
116+ use_metadata : bool = True ,
117117 ocr_kwargs : Optional [dict ] = None ,
118+ ad_hoc_recognizers : Optional [List [PatternRecognizer ]] = None ,
118119 ** text_analyzer_kwargs ,
119120 ) -> Tuple [Optional [PIL .Image .Image ], dict ]:
120121 """Evaluate performance for a single DICOM instance.
@@ -124,7 +125,11 @@ def eval_dicom_instance(
124125 :param padding_width: Padding width to use when running OCR.
125126 :param tolerance: Pixel distance tolerance for matching to ground truth.
126127 :param display_image: If the verificationimage is displayed and returned.
128+ :param use_metadata: Whether to redact text in the image that
129+ are present in the metadata.
127130 :param ocr_kwargs: Additional params for OCR methods.
131+ :param ad_hoc_recognizers: List of PatternRecognizer objects to use
132+ for ad-hoc recognizer.
128133 :param text_analyzer_kwargs: Additional values for the analyze method
129134 in ImageAnalyzerEngine.
130135
@@ -135,7 +140,9 @@ def eval_dicom_instance(
135140 instance ,
136141 padding_width ,
137142 display_image ,
143+ use_metadata ,
138144 ocr_kwargs = ocr_kwargs ,
145+ ad_hoc_recognizers = ad_hoc_recognizers ,
139146 ** text_analyzer_kwargs ,
140147 )
141148 formatted_ocr_results = self .bbox_processor .get_bboxes_from_ocr_results (
0 commit comments