Presidio Image Redactor API Reference
ImageRedactorEngine class
ImageRedactorEngine performs OCR + PII detection + bounding box redaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_analyzer_engine |
ImageAnalyzerEngine
|
Engine which performs OCR + PII detection. |
None
|
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_redactor_engine.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
redact(image, fill=(0, 0, 0), ocr_kwargs=None, **text_analyzer_kwargs)
Redact method to redact the given image.
Please notice, this method duplicates the image, creates a new instance and manipulate it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Image
|
PIL Image to be processed. |
required |
fill |
Union[int, Tuple[int, int, int]]
|
colour to fill the shape - int (0-255) for grayscale or Tuple(R, G, B) for RGB. |
(0, 0, 0)
|
ocr_kwargs |
Optional[dict]
|
Additional params for OCR methods. |
None
|
text_analyzer_kwargs |
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Image
|
the redacted image |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_redactor_engine.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
ImageAnalyzerEngine class
ImageAnalyzerEngine class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
analyzer_engine |
Optional[AnalyzerEngine]
|
The Presidio AnalyzerEngine instance to be used to detect PII in text |
None
|
ocr |
Optional[OCR]
|
the OCR object to be used to detect text in images. |
None
|
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_analyzer_engine.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
analyze(image, ocr_kwargs=None, **text_analyzer_kwargs)
Analyse method to analyse the given image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
object
|
PIL Image/numpy array or file path(str) to be processed. |
required |
ocr_kwargs |
Optional[dict]
|
Additional params for OCR methods. |
None
|
text_analyzer_kwargs |
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
List[ImageRecognizerResult]
|
List of the extract entities with image bounding boxes. |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_analyzer_engine.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
map_analyzer_results_to_bounding_boxes(text_analyzer_results, ocr_result, text)
staticmethod
Map extracted PII entities to image bounding boxes.
Matching is based on the position of the recognized entity from analyzer and word (in ocr dict) in the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_analyzer_results |
List[RecognizerResult]
|
PII entities recognized by presidio analyzer |
required |
ocr_result |
dict
|
dict results with words and bboxes from OCR |
required |
text |
str
|
text the results are based on return: list of extracted entities with image bounding boxes |
required |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_analyzer_engine.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
threshold_ocr_result(ocr_result, ocr_threshold)
staticmethod
Filter out OCR results below confidence threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_result |
dict
|
OCR results (raw). |
required |
ocr_threshold |
float
|
Threshold value between -1 and 100. |
required |
Returns:
Type | Description |
---|---|
dict
|
OCR results with low confidence items removed. |
Source code in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/presidio_image_redactor/image_analyzer_engine.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|