From 678aeab7a590e73be14f0c41a77e35049fcbae63 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 24 Apr 2025 11:41:46 +0200 Subject: [PATCH] feat: implemented effective but non generative impainting --- secure_pixelation/pixelation_process.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/secure_pixelation/pixelation_process.py b/secure_pixelation/pixelation_process.py index 65f7a06..1bcc4a3 100644 --- a/secure_pixelation/pixelation_process.py +++ b/secure_pixelation/pixelation_process.py @@ -1,5 +1,6 @@ from __future__ import annotations +from typing import Optional from pathlib import Path import cv2 @@ -17,6 +18,19 @@ def blackout(raw_image: RawImage) -> np.ndarray: return image +def impaint(raw_image: RawImage, image: Optional[np.ndarray] = None) -> np.ndarray: + image = image if image is not None else raw_image.get_image() + + # Create a mask where blacked-out areas are marked as 255 (white) + mask = np.zeros(image.shape[:2], dtype=np.uint8) + + for (x, y, w, h) in raw_image.bounding_boxes: + mask[y:y+h, x:x+w] = 255 + + # Apply inpainting using the Telea method + return cv2.inpaint(image, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA) + + def pixelate(to_detect: str, debug_drawings: bool = True): raw_image = RawImage(to_detect) @@ -34,3 +48,6 @@ def pixelate(to_detect: str, debug_drawings: bool = True): step_1 = blackout(raw_image) write_image(step_1, "step_1") + + step_2 = impaint(raw_image, image=step_1) + write_image(step_2, "step_2")