Presidio Image Redactor API Reference
Image Redactor root module.
BboxProcessor
Common module for general bounding box operators.
Source code in presidio_image_redactor/bbox.py
6 7 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 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 182 183 184 185 186 187 188 189 190 |
|
get_bboxes_from_analyzer_results(analyzer_results)
staticmethod
Organize bounding box info from analyzer results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
analyzer_results
|
List[ImageRecognizerResult]
|
Results from using ImageAnalyzerEngine. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Union[str, float, int]]]
|
Bounding box info organized. |
Source code in presidio_image_redactor/bbox.py
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 |
|
get_bboxes_from_ocr_results(ocr_results)
staticmethod
Get bounding boxes on padded image for all detected words from ocr_results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_results
|
Dict[str, List[Union[int, str]]]
|
Raw results from OCR. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Union[int, float, str]]]
|
Bounding box information per word. |
Source code in presidio_image_redactor/bbox.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 |
|
match_with_source(all_pos, pii_source_dict, detected_pii, tolerance=50)
staticmethod
Match returned redacted PII bbox data with some source of truth for PII.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_pos
|
List[Dict[str, Union[str, int, float]]]
|
Dictionary storing all positives. |
required |
pii_source_dict
|
List[Dict[str, Union[str, int, float]]]
|
List of PII labels for this instance. |
required |
detected_pii
|
Dict[str, Union[str, float, int]]
|
Detected PII (single entity from analyzer_results). |
required |
tolerance
|
int
|
Tolerance for exact coordinates and size data. |
50
|
Returns:
Type | Description |
---|---|
Tuple[List[Dict[str, Union[str, int, float]]], bool]
|
List of all positive with PII mapped back as possible and whether a match was found. |
Source code in presidio_image_redactor/bbox.py
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 182 183 184 185 186 187 188 189 190 |
|
remove_bbox_padding(analyzer_bboxes, padding_width)
staticmethod
Remove added padding in bounding box coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
analyzer_bboxes
|
List[Dict[str, Union[str, float, int]]]
|
The bounding boxes from analyzer results. |
required |
padding_width
|
int
|
Pixel width used for padding (0 if no padding). |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, int]]
|
Bounding box information per word. |
Source code in presidio_image_redactor/bbox.py
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 |
|
BilateralFilter
Bases: ImagePreprocessor
BilateralFilter class.
The class applies bilateral filtering to an image. and returns the filtered image and metadata.
Source code in presidio_image_redactor/image_processing_engine.py
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 |
|
__init__(diameter=3, sigma_color=40, sigma_space=40)
Initialize the BilateralFilter class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diameter
|
int
|
Diameter of each pixel neighborhood. |
3
|
sigma_color
|
int
|
value of sigma in the color space. |
40
|
sigma_space
|
int
|
value of sigma in the coordinate space. |
40
|
Source code in presidio_image_redactor/image_processing_engine.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
preprocess_image(image)
Preprocess the image to be analyzed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Loaded PIL image. |
required |
Returns:
Type | Description |
---|---|
Tuple[Image, dict]
|
The processed image and metadata (diameter, sigma_color, sigma_space). |
Source code in presidio_image_redactor/image_processing_engine.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
ContrastSegmentedImageEnhancer
Bases: ImagePreprocessor
Class containing all logic to perform contrastive segmentation.
Contrastive segmentation is a preprocessing step that aims to enhance the text in an image by increasing the contrast between the text and the background. The parameters used to run the preprocessing are selected based on the contrast level of the image.
Source code in presidio_image_redactor/image_processing_engine.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
__init__(bilateral_filter=None, adaptive_threshold=None, image_rescaling=None, low_contrast_threshold=40)
Initialize the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bilateral_filter
|
Optional[BilateralFilter]
|
Optional BilateralFilter instance. |
None
|
adaptive_threshold
|
Optional[SegmentedAdaptiveThreshold]
|
Optional AdaptiveThreshold instance. |
None
|
image_rescaling
|
Optional[ImageRescaling]
|
Optional ImageRescaling instance. |
None
|
low_contrast_threshold
|
int
|
Threshold for low contrast images. |
40
|
Source code in presidio_image_redactor/image_processing_engine.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
preprocess_image(image)
Preprocess the image to be analyzed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Loaded PIL image. |
required |
Returns:
Type | Description |
---|---|
Tuple[Image, dict]
|
The processed image and metadata (background color, scale percentage, contrast level, and C value). |
Source code in presidio_image_redactor/image_processing_engine.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
DicomImagePiiVerifyEngine
Bases: ImagePiiVerifyEngine
, DicomImageRedactorEngine
Class to handle verification and evaluation for DICOM de-identification.
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__init__(ocr_engine=None, image_analyzer_engine=None)
Initialize DicomImagePiiVerifyEngine object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_engine
|
Optional[OCR]
|
OCR engine to use. |
None
|
image_analyzer_engine
|
Optional[ImageAnalyzerEngine]
|
Image analyzer engine to use. |
None
|
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
calculate_precision(gt, all_pos)
staticmethod
Calculate precision.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt
|
List[dict]
|
List of ground truth labels. |
required |
all_pos
|
List[dict]
|
All Detected PHI (mapped back to have actual PHI text). |
required |
Returns:
Type | Description |
---|---|
float
|
Precision value. |
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
calculate_recall(gt, all_pos)
staticmethod
Calculate recall.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt
|
List[dict]
|
List of ground truth labels. |
required |
all_pos
|
List[dict]
|
All Detected PHI (mapped back to have actual PHI text). |
required |
Returns:
Type | Description |
---|---|
float
|
Recall value. |
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
eval_dicom_instance(instance, ground_truth, padding_width=25, tolerance=50, display_image=False, use_metadata=True, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Evaluate performance for a single DICOM instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
FileDataset
|
Loaded DICOM instance including pixel data and metadata. |
required |
ground_truth
|
dict
|
Dictionary containing ground truth labels for the instance. |
required |
padding_width
|
int
|
Padding width to use when running OCR. |
25
|
tolerance
|
int
|
Pixel distance tolerance for matching to ground truth. |
50
|
display_image
|
bool
|
If the verificationimage is displayed and returned. |
False
|
use_metadata
|
bool
|
Whether to redact text in the image that are present in the metadata. |
True
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in ImageAnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[Optional[Image], dict]
|
Evaluation comparing redactor engine results vs ground truth. |
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
verify_dicom_instance(instance, padding_width=25, display_image=True, show_text_annotation=True, use_metadata=True, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Verify PII on a single DICOM instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
FileDataset
|
Loaded DICOM instance including pixel data and metadata. |
required |
padding_width
|
int
|
Padding width to use when running OCR. |
25
|
display_image
|
bool
|
If the verificationimage is displayed and returned. |
True
|
show_text_annotation
|
bool
|
True to display entity type when displaying image with bounding boxes. |
True
|
use_metadata
|
bool
|
Whether to redact text in the image that are present in the metadata. |
True
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in ImageAnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[Optional[Image], dict, list]
|
Image with boxes identifying PHI, OCR results, and analyzer results. |
Source code in presidio_image_redactor/dicom_image_pii_verify_engine.py
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 |
|
DicomImageRedactorEngine
Bases: 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 presidio_image_redactor/dicom_image_redactor_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
|
augment_word(word, case_sensitive=False)
staticmethod
Apply multiple types of casing to the provided string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
words
|
String containing the word or term of interest. |
required | |
case_sensitive
|
bool
|
True if we want to preserve casing. |
False
|
Returns:
Type | Description |
---|---|
list
|
List of the same string with different casings and spacing. |
Source code in presidio_image_redactor/dicom_image_redactor_engine.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
redact(image, fill='contrast', padding_width=25, crop_ratio=0.75, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Redact method to redact the given DICOM image.
Please note, this method duplicates the image, creates a new instance and manipulates it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
FileDataset
|
Loaded DICOM instance including pixel data and metadata. |
required |
fill
|
str
|
Fill setting to use for redaction box ("contrast" or "background"). |
'contrast'
|
padding_width
|
int
|
Padding width to use when running OCR. |
25
|
crop_ratio
|
float
|
Portion of image to consider when selecting most common pixel value as the background color value. |
0.75
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
FileDataset
|
DICOM instance with redacted pixel data. |
Source code in presidio_image_redactor/dicom_image_redactor_engine.py
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 |
|
redact_and_return_bbox(image, fill='contrast', padding_width=25, crop_ratio=0.75, use_metadata=True, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Redact method to redact the given DICOM image and return redacted bboxes.
Please note, this method duplicates the image, creates a new instance and manipulates it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
FileDataset
|
Loaded DICOM instance including pixel data and metadata. |
required |
fill
|
str
|
Fill setting to use for redaction box ("contrast" or "background"). |
'contrast'
|
padding_width
|
int
|
Padding width to use when running OCR. |
25
|
crop_ratio
|
float
|
Portion of image to consider when selecting most common pixel value as the background color value. |
0.75
|
use_metadata
|
bool
|
Whether to redact text in the image that are present in the metadata. |
True
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[FileDataset, List[Dict[str, int]]]
|
DICOM instance with redacted pixel data. |
Source code in presidio_image_redactor/dicom_image_redactor_engine.py
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 |
|
redact_from_directory(input_dicom_path, output_dir, padding_width=25, crop_ratio=0.75, fill='contrast', use_metadata=True, save_bboxes=False, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Redact method to redact from a directory of files.
Please notice, this method duplicates the files, creates new instances and manipulate them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dicom_path
|
str
|
String path to directory of DICOM images. |
required |
output_dir
|
str
|
String path to parent output directory. |
required |
|
padding_width
|
Padding width to use when running OCR. |
required |
crop_ratio
|
float
|
Portion of image to consider when selecting most common pixel value as the background color value. |
0.75
|
fill
|
str
|
Color setting to use for redaction box ("contrast" or "background"). |
'contrast'
|
use_metadata
|
bool
|
Whether to redact text in the image that are present in the metadata. |
True
|
save_bboxes
|
bool
|
True if we want to save boundings boxes. |
False
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Source code in presidio_image_redactor/dicom_image_redactor_engine.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
redact_from_file(input_dicom_path, output_dir, padding_width=25, crop_ratio=0.75, fill='contrast', use_metadata=True, save_bboxes=False, verbose=True, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Redact method to redact from a given file.
Please notice, this method duplicates the file, creates new instance and manipulate them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dicom_path
|
str
|
String path to DICOM image. |
required |
output_dir
|
str
|
String path to parent output directory. |
required |
|
padding_width
|
Padding width to use when running OCR. |
required |
fill
|
str
|
Color setting to use for redaction box ("contrast" or "background"). |
'contrast'
|
use_metadata
|
bool
|
Whether to redact text in the image that are present in the metadata. |
True
|
save_bboxes
|
bool
|
True if we want to save boundings boxes. |
False
|
verbose
|
bool
|
True to print where redacted file was written to. |
True
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Source code in presidio_image_redactor/dicom_image_redactor_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
DocumentIntelligenceOCR
Bases: OCR
OCR class that uses Azure AI Document Intelligence OCR engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Optional[str]
|
The API key |
None
|
endpoint
|
Optional[str]
|
The API endpoint |
None
|
model_id
|
Optional[str]
|
Which model to use For details, see https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/ |
'prebuilt-document'
|
Source code in presidio_image_redactor/document_intelligence_ocr.py
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 |
|
analyze_document(imgbytes, **kwargs)
Analyze the document and return the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imgbytes
|
bytes
|
The bytes to send to the API endpoint |
required |
kwargs
|
additional arguments for begin_analyze_document |
{}
|
Source code in presidio_image_redactor/document_intelligence_ocr.py
147 148 149 150 151 152 153 154 155 156 |
|
get_imgbytes(image)
Retrieve the image bytes from the image object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Union[bytes, ndarray, Image]
|
Any of bytes/numpy array /PIL image object |
required |
Source code in presidio_image_redactor/document_intelligence_ocr.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
perform_ocr(image, **kwargs)
Perform OCR on the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
object
|
PIL Image/numpy array or file path(str) to be processed |
required |
kwargs
|
Additional values for begin_analyze_document |
{}
|
Returns:
Type | Description |
---|---|
dict
|
results dictionary containing bboxes and text for each detected word |
Source code in presidio_image_redactor/document_intelligence_ocr.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
ImageAnalyzerEngine
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
|
image_preprocessor
|
Optional[ImagePreprocessor]
|
The ImagePreprocessor object to be used to preprocess the image |
None
|
Source code in presidio_image_redactor/image_analyzer_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
add_custom_bboxes(image, bboxes, show_text_annotation=True, use_greyscale_cmap=False)
classmethod
Add custom bounding boxes to image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Standard image of DICOM pixels. |
required |
bboxes
|
List[dict]
|
List of bounding boxes to display (with is_PII field). |
required |
gt_bboxes
|
Ground truth bboxes (list of dictionaries). |
required | |
show_text_annotation
|
bool
|
True if you want text annotation for PHI status to display. |
True
|
use_greyscale_cmap
|
bool
|
Use greyscale color map. |
False
|
Returns:
Type | Description |
---|---|
Image
|
Image with bounding boxes drawn on. |
Source code in presidio_image_redactor/image_analyzer_engine.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
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 presidio_image_redactor/image_analyzer_engine.py
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 |
|
fig2img(fig)
staticmethod
Convert a Matplotlib figure to a PIL Image and return it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Matplotlib figure. |
required |
Returns:
Type | Description |
---|---|
Image
|
Image of figure. |
Source code in presidio_image_redactor/image_analyzer_engine.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
get_pii_bboxes(ocr_bboxes, analyzer_bboxes)
staticmethod
Get a list of bboxes with is_PII property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_bboxes
|
List[dict]
|
Bboxes from OCR results. |
required |
analyzer_bboxes
|
List[dict]
|
Bboxes from analyzer results. |
required |
Returns:
Type | Description |
---|---|
List[dict]
|
All bboxes with appropriate label for whether it is PHI or not. |
Source code in presidio_image_redactor/image_analyzer_engine.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
map_analyzer_results_to_bounding_boxes(text_analyzer_results, ocr_result, text, allow_list)
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 |
required |
allow_list
|
List[str]
|
List of words to not redact return: list of extracted entities with image bounding boxes |
required |
Source code in presidio_image_redactor/image_analyzer_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
remove_space_boxes(ocr_result)
staticmethod
Remove OCR bboxes that are for spaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_result
|
dict
|
OCR results (raw or thresholded). |
required |
Returns:
Type | Description |
---|---|
dict
|
OCR results with empty words removed. |
Source code in presidio_image_redactor/image_analyzer_engine.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
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 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 |
|
ImagePiiVerifyEngine
Bases: ImageRedactorEngine
ImagePiiVerifyEngine class only supporting Pii verification currently.
Source code in presidio_image_redactor/image_pii_verify_engine.py
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 |
|
verify(image, is_greyscale=False, display_image=True, show_text_annotation=True, ocr_kwargs=None, ad_hoc_recognizers=None, **text_analyzer_kwargs)
Annotate image with the detect PII entity.
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 |
is_greyscale
|
bool
|
Whether the image is greyscale or not. |
False
|
display_image
|
bool
|
If the verificationimage is displayed and returned. |
True
|
show_text_annotation
|
bool
|
True to display entity type when displaying image with bounding boxes. |
True
|
ocr_kwargs
|
Optional[dict]
|
Additional params for OCR methods. |
None
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in ImageAnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Image
|
the annotated image |
Source code in presidio_image_redactor/image_pii_verify_engine.py
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 |
|
ImagePreprocessor
ImagePreprocessor class.
Parent class for image preprocessing objects.
Source code in presidio_image_redactor/image_processing_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 |
|
__init__(use_greyscale=True)
Initialize the ImagePreprocessor class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_greyscale
|
bool
|
Whether to convert the image to greyscale. |
True
|
Source code in presidio_image_redactor/image_processing_engine.py
15 16 17 18 19 20 |
|
convert_image_to_array(image)
Convert PIL image to numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Loaded PIL image. |
required |
convert_to_greyscale
|
Whether to convert the image to greyscale. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
image pixels as a numpy array. |
Source code in presidio_image_redactor/image_processing_engine.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
preprocess_image(image)
Preprocess the image to be analyzed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Loaded PIL image. |
required |
Returns:
Type | Description |
---|---|
Tuple[Image, dict]
|
The processed image and any metadata regarding the preprocessing approach. |
Source code in presidio_image_redactor/image_processing_engine.py
22 23 24 25 26 27 28 29 30 |
|
ImageRedactorEngine
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 presidio_image_redactor/image_redactor_engine.py
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 |
|
redact(image, fill=(0, 0, 0), ocr_kwargs=None, ad_hoc_recognizers=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
|
ad_hoc_recognizers
|
Optional[List[PatternRecognizer]]
|
List of PatternRecognizer objects to use for ad-hoc recognizer. |
None
|
text_analyzer_kwargs
|
Additional values for the analyze method in AnalyzerEngine. |
{}
|
Returns:
Type | Description |
---|---|
Image
|
the redacted image |
Source code in presidio_image_redactor/image_redactor_engine.py
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 |
|
ImageRescaling
Bases: ImagePreprocessor
ImageRescaling class. Rescales images based on their size.
Source code in presidio_image_redactor/image_processing_engine.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
__init__(small_size=1048576, large_size=4000000, factor=2, interpolation=cv2.INTER_AREA)
Initialize the ImageRescaling class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
small_size
|
int
|
Threshold for small image size. |
1048576
|
large_size
|
int
|
Threshold for large image size. |
4000000
|
factor
|
int
|
Scaling factor for resizing. |
2
|
interpolation
|
int
|
Interpolation method for resizing. |
INTER_AREA
|
Source code in presidio_image_redactor/image_processing_engine.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
preprocess_image(image)
Preprocess the image to be analyzed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
Loaded PIL image. |
required |
Returns:
Type | Description |
---|---|
Tuple[Image, dict]
|
The processed image and metadata (scale_factor). |
Source code in presidio_image_redactor/image_processing_engine.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
OCR
Bases: ABC
OCR class that performs OCR on a given image.
Source code in presidio_image_redactor/ocr.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
get_text_from_ocr_dict(ocr_result, separator=' ')
staticmethod
Combine the text from the OCR dict to full text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_result
|
dict
|
dictionary containing the ocr results per word |
required |
separator
|
str
|
separator to use when joining the words return: str containing the full extracted text as string |
' '
|
Source code in presidio_image_redactor/ocr.py
18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
perform_ocr(image, **kwargs)
abstractmethod
Perform OCR on a given image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
object
|
PIL Image/numpy array or file path(str) to be processed |
required |
kwargs
|
Additional values for perform OCR method |
{}
|
Returns:
Type | Description |
---|---|
dict
|
results dictionary containing bboxes and text for each detected word |
Source code in presidio_image_redactor/ocr.py
7 8 9 10 11 12 13 14 15 16 |
|
SegmentedAdaptiveThreshold
Bases: ImagePreprocessor
SegmentedAdaptiveThreshold class.
The class applies adaptive thresholding to an image and returns the thresholded image and metadata. The parameters used to run the adaptivethresholding are selected based on the contrast level of the image.
Source code in presidio_image_redactor/image_processing_engine.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
__init__(block_size=5, contrast_threshold=40, c_low_contrast=10, c_high_contrast=40, bg_threshold=122)
Initialize the SegmentedAdaptiveThreshold class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_size
|
int
|
Size of the neighborhood area for threshold calculation. |
5
|
contrast_threshold
|
int
|
Threshold for low contrast images. |
40
|
C_low_contrast
|
Constant added to the mean for low contrast images. |
required | |
C_high_contrast
|
Constant added to the mean for high contrast images. |
required | |
bg_threshold
|
int
|
Threshold for background color. |
122
|
Source code in presidio_image_redactor/image_processing_engine.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
preprocess_image(image)
Preprocess the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Union[Image, ndarray]
|
Loaded PIL image. |
required |
Returns:
Type | Description |
---|---|
Tuple[Image, dict]
|
The processed image and metadata (C, background_color, contrast). |
Source code in presidio_image_redactor/image_processing_engine.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
TesseractOCR
Bases: OCR
OCR class that performs OCR on a given image.
Source code in presidio_image_redactor/tesseract_ocr.py
6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
perform_ocr(image, **kwargs)
Perform OCR on a given image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
object
|
PIL Image/numpy array or file path(str) to be processed |
required |
kwargs
|
Additional values for OCR image_to_data |
{}
|
Returns:
Type | Description |
---|---|
dict
|
results dictionary containing bboxes and text for each detected word |
Source code in presidio_image_redactor/tesseract_ocr.py
9 10 11 12 13 14 15 16 17 18 |
|