Plot custom bounding boxes¶
This notebook covers how to use the image verification engines to plot custom bounding boxes. This can be helpful when you want to verify a provided set of bounding boxes against an image.
Prerequisites¶
Before getting started, make sure presidio and the latest version of Tesseract OCR are installed. For detailed documentation, see the installation docs.
!pip install presidio_analyzer presidio_anonymizer presidio_image_redactor
!python -m spacy download en_core_web_lg
0. Imports and initializations¶
from PIL import Image
import pydicom
from presidio_image_redactor import ImageAnalyzerEngine, ImagePiiVerifyEngine, DicomImagePiiVerifyEngine
import matplotlib.pyplot as plt
Initialize engines used for image redaction
# Image analyzer engine
image_analyzer_engine = ImageAnalyzerEngine()
# Verification engines
verify_engine = ImagePiiVerifyEngine() # standard images
dicom_verify_engine = DicomImagePiiVerifyEngine() # DICOM images
padding_width = 3
1. Example images¶
In this notebook, we will use the following examples images.
1.1 Standard example image¶
image = Image.open("../../image-redactor/ocr_text.png")
display(image)
And this is what the image looks like with the standard, default behavior of the verification engine.
verify_image = verify_engine.verify(image, display_image=True)
1.2 DICOM medical image¶
For more information on DICOM image redaction, please see example_dicom_image_redactor.ipynb and the Image redactor module documentation.
instance = pydicom.dcmread("./sample_data/0_ORIGINAL.dcm")
plt.imshow(instance.pixel_array, cmap="gray")
<matplotlib.image.AxesImage at 0x1f2a91512b0>
And this is what the image looks like with the standard, default behavior verification.
dicom_image, dicom_ocr_bboxes, dicom_analyzer_bboxes = dicom_verify_engine.verify_dicom_instance(
instance,
padding_width=padding_width,
display_image=True
)