generated from Hazel/python-project
feat: added proper pixelation
This commit is contained in:
parent
678aeab7a5
commit
ad38eef03b
@ -31,6 +31,22 @@ def impaint(raw_image: RawImage, image: Optional[np.ndarray] = None) -> np.ndarr
|
||||
return cv2.inpaint(image, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
||||
|
||||
|
||||
|
||||
def pixelate_regions(raw_image: RawImage, image: Optional[np.ndarray] = None, pixel_size: int = 10) -> np.ndarray:
|
||||
image = image.copy() if image is not None else raw_image.get_image().copy()
|
||||
|
||||
for (x, y, w, h) in raw_image.bounding_boxes:
|
||||
roi = image[y:y+h, x:x+w]
|
||||
|
||||
# Resize down and then back up
|
||||
temp = cv2.resize(roi, (max(1, w // pixel_size), max(1, h // pixel_size)), interpolation=cv2.INTER_LINEAR)
|
||||
pixelated = cv2.resize(temp, (w, h), interpolation=cv2.INTER_NEAREST)
|
||||
|
||||
image[y:y+h, x:x+w] = pixelated
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def pixelate(to_detect: str, debug_drawings: bool = True):
|
||||
raw_image = RawImage(to_detect)
|
||||
|
||||
@ -46,8 +62,13 @@ def pixelate(to_detect: str, debug_drawings: bool = True):
|
||||
|
||||
cv2.imwrite(f, image)
|
||||
|
||||
write_image(raw_image.image, "step_0")
|
||||
|
||||
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")
|
||||
|
||||
step_3 = pixelate_regions(raw_image, image=step_2)
|
||||
write_image(step_3, "step_3")
|
||||
|
Loading…
x
Reference in New Issue
Block a user