generated from Hazel/python-project
feat: implemented effective but non generative impainting
This commit is contained in:
parent
180b41ffa4
commit
678aeab7a5
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@ -17,6 +18,19 @@ def blackout(raw_image: RawImage) -> np.ndarray:
|
|||||||
return image
|
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):
|
def pixelate(to_detect: str, debug_drawings: bool = True):
|
||||||
raw_image = RawImage(to_detect)
|
raw_image = RawImage(to_detect)
|
||||||
|
|
||||||
@ -34,3 +48,6 @@ def pixelate(to_detect: str, debug_drawings: bool = True):
|
|||||||
|
|
||||||
step_1 = blackout(raw_image)
|
step_1 = blackout(raw_image)
|
||||||
write_image(step_1, "step_1")
|
write_image(step_1, "step_1")
|
||||||
|
|
||||||
|
step_2 = impaint(raw_image, image=step_1)
|
||||||
|
write_image(step_2, "step_2")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user