Skip to content

Commit

Permalink
Merge branch 'main' into issue_718
Browse files Browse the repository at this point in the history
  • Loading branch information
rakan41 authored Aug 11, 2021
2 parents d33b4e1 + 26e57b8 commit a352de5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def __init__(self, image_analyzer_engine: ImageAnalyzerEngine = None):
self.image_analyzer_engine = image_analyzer_engine

def redact(
self, image: Image, fill: Union[int, Tuple[int, int, int]] = (0, 0, 0)
self, image: Image,
fill: Union[int, Tuple[int, int, int]] = (0, 0, 0),
**kwargs,
) -> Image:
"""Redact method to redact the given image.
Expand All @@ -27,13 +29,14 @@ def redact(
:param image: PIL Image to be processed
:param fill: colour to fill the shape - int (0-255) for
grayscale or Tuple(R, G, B) for RGB
:param kwargs: Additional values for the analyze method in AnalyzerEngine
:return: the redacted image
"""

image = ImageChops.duplicate(image)

bboxes = self.image_analyzer_engine.analyze(image)
bboxes = self.image_analyzer_engine.analyze(image, **kwargs)
draw = ImageDraw.Draw(image)

for box in bboxes:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_given_image_without_text_and_fill_then_image_does_not_change():
redacted_image = ImageRedactorEngine().redact(image, red_fill)
assert compare_images(redacted_image, image)


def test_given_two_word_entity_then_no_extra_bounding_box_appears():
"""Tests bounding boxes for multiword entities.
Expand All @@ -45,3 +45,17 @@ def test_given_two_word_entity_then_no_extra_bounding_box_appears():

redacted_image = ImageRedactorEngine().redact(image, red_fill)
assert compare_images(expected_image, redacted_image)


def test_given_analzyer_kwargs_then_different_entities_are_redacted():
"""
Tests that kwargs such as entities and score_threshold are available for redact method
"""
# Image with PII entities
image = get_resource_image("kwargs_test.jpg")
redacted_image_no_args = ImageRedactorEngine().redact(image)
redacted_image_entities_args = ImageRedactorEngine().redact(image, entities=['PERSON', 'LOCATION'])
redacted_image_score_args = ImageRedactorEngine().redact(image, score_threshold=1)
assert not compare_images(redacted_image_no_args, redacted_image_entities_args)
assert not compare_images(redacted_image_no_args, redacted_image_score_args)
assert not compare_images(redacted_image_entities_args, redacted_image_score_args)

0 comments on commit a352de5

Please sign in to comment.