跳转到主要内容

Presidio图像编辑器包

项目描述

Presidio Image Redactor

请注意,此包仍处于alpha版本,尚未准备好投入生产。

描述

Presidio图像编辑器是一个基于Python的模块,用于检测和编辑图像中的PII文本实体。

将Presidio图像编辑器部署到Azure

使用以下按钮将presidio图像编辑器部署到您的Azure订阅。

Deploy to Azure

标准图像处理流程

Image Redactor Design

处理DICOM文件

DICOM image Redactor Design

安装

先决条件

  • 按照为您的操作系统安装Tesseract OCR的说明进行安装。

    为了获得最佳性能,请使用最新版本的Tesseract OCR。Presidio已与v5.2.0进行了测试。

作为包

要开始使用Presidio-image-redactor,请运行以下命令

pip install presidio-image-redactor

安装完成后,运行以下命令下载Presidio Analyzer所需的默认spacy模型

python -m spacy download en_core_web_lg

入门(标准图像类型)

引擎将接收2个参数

  1. 要编辑的图像。
  2. 用于编辑红色的颜色填充,默认颜色填充为黑色。可以是整数或元组(0,0,0)。
from PIL import Image
from presidio_image_redactor import ImageRedactorEngine

# Get the image to redact using PIL lib (pillow)
image = Image.open("presidio-image-redactor/tests/integration/resources/ocr_test.png")

# Initialize the engine
engine = ImageRedactorEngine()

# Redact the image with pink color
redacted_image = engine.redact(image, (255, 192, 203))

# save the redacted image 
redacted_image.save("new_image.png")
# uncomment to open the image for viewing
# redacted_image.show()

作为docker服务

在文件夹presidio/presidio-image-redactor中运行

docker-compose up -d

HTTP API

编辑

接收一个图像和颜色填充(可选,默认为黑色)。编辑图像的PII文本并返回一个新的编辑后的图像。

POST /redact

有效载荷

以multipart-form形式发送。包含图像文件和所需颜色填充的数据。

{
  "data": "{'color_fill':'0,0,0'}"
}

结果

200 OK

curl示例

# use ocr_test.png as the image to redact, and 255 as the color fill. 
# out.png is the new redacted image received from the server.
curl -XPOST "http://localhost:3000/redact" -H "content-type: multipart/form-data" -F "image=@ocr_test.png" -F "data=\"{'color_fill':'255'}\"" > out.png

Python脚本示例可以在以下路径找到:/presidio/e2e-tests/tests/test_image_redactor.py

入门(DICOM图像)

此模块仅编辑像素数据,不擦除DICOM元数据中可能存在的文本PHI。

我们强烈建议在使用DICOM图像编辑器擦除图像中的文本之前先擦除元数据PHI。要从元数据中擦除敏感信息,请考虑使用其他软件包,例如健康数据匿名化工具

要擦除DICOM图像中嵌入的文本PHI,请参阅以下示例代码

import pydicom
from presidio_image_redactor import DicomImageRedactorEngine

# Set input and output paths
input_path = "path/to/your/dicom/file.dcm"
output_dir = "./output"

# Initialize the engine
engine = DicomImageRedactorEngine()

# Option 1: Redact from a loaded DICOM image
dicom_image = pydicom.dcmread(input_path)
redacted_dicom_image = engine.redact(dicom_image, fill="contrast")

# Option 2: Redact from a loaded DICOM image and return redacted regions
redacted_dicom_image, bboxes = engine.redact_and_return_bbox(dicom_image, fill="contrast")

# Option 3: Redact from DICOM file and save redacted regions as json file
engine.redact_from_file(input_path, output_dir, padding_width=25, fill="contrast", save_bboxes=True)

# Option 4: Redact from directory and save redacted regions as json files
ocr_kwargs = {"ocr_threshold": 50}
engine.redact_from_directory("path/to/your/dicom", output_dir, fill="background", save_bboxes=True, ocr_kwargs=ocr_kwargs)

有关更多详细信息以及输出结果的视觉确认,请参阅示例笔记本:docs/samples/python/example_dicom_image_redactor.ipynb

Windows系统注意事项

如果您使用的是Windows机器,如果文件路径过长,可能会遇到问题。不幸的是,当处理通常嵌套在具有描述性名称的目录中的DICOM图像时,这种情况并不罕见。

为了避免由于文件路径中的字符长度导致代码无法识别路径为存在而引起的错误,请在您的系统上启用长路径

DICOM数据引用

用于对DicomImageRedactorEngine进行单元和集成测试的DICOM数据已获得原始数据集所有者的许可存储在本存储库中。请参阅以下数据集信息

Rutherford, M., Mun, S.K., Levine, B., Bennett, W.C., Smith, K., Farmer, P., Jarosz, J., Wagner, U., Farahani, K., Prior, F. (2021). A DICOM dataset for evaluation of medical image de-identification (Pseudo-PHI-DICOM-Data) [Data set]. The Cancer Imaging Archive. DOI: https://doi.org/10.7937/s17z-r072

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

此版本没有可用的源代码分发文件。请参阅生成分发存档的教程

构建的分发

presidio_image_redactor-0.0.53-py3-none-any.whl (34.2 kB 查看哈希值)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面