Files

29 lines
965 B
Python

import numpy as np
from obfuscation.base_obfuscation_technique import ObfuscationTechnique
import random
class Randoming(ObfuscationTechnique):
"""
Fill only the masked region of the face ROI with random colours.
"""
def __init__(self):
pass
def obfuscate(self, face_roi_img_bgr: np.ndarray, face_mask) -> np.ndarray:
# 1) start from original
obf = face_roi_img_bgr.copy()
# 2) build a full random-coloured image of same shape
rand_img = np.empty_like(face_roi_img_bgr)
h, w = rand_img.shape[:2]
for i in range(h):
for j in range(w):
rand_img[i, j] = (random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255))
# 3) apply only in mask
obf[face_mask.astype(bool)] = rand_img[face_mask.astype(bool)]
return obf
def name(self):
return "Random"