FoundHand / tmp.py
chaerinmin's picture
brush examples, visualize crop
6b70bd5
raw
history blame
783 Bytes
import glob
import os
from PIL import Image
import numpy as np
img_dir = "bad_hands"
masked_paths = sorted(glob.glob(os.path.join(img_dir, "*_mask.jpg")))
for masked_pth in masked_paths:
img_path = masked_pth.replace("_mask.jpg", ".jpg")
assert os.path.exists(img_path), f"Image path {img_path} does not exist."
masked = np.array(Image.open(masked_pth))
mask = (np.all(masked > 245, axis=-1)).astype(np.uint8)*128 + 64
img = np.array(Image.open(img_path))
composite = np.concatenate((img, mask[..., None]), axis=-1)
# img.putalpha(Image.fromarray(mask))
composite = Image.fromarray(composite)
composite.save(masked_pth.replace("_mask.jpg", "_composite.png"))
print(f"Saved composite image {masked_pth.replace('_mask.jpg', '_composite.png')}")