3D: square mesh input, paint_mesh projection painter, cutout_ai
generate_mesh pads portrait images to a white square (CLIPVisionEncode centre-crops, which cut off helmet and feet). paint_mesh cleans a Hunyuan3D shape, projects front/back views onto it with z-buffer visibility and writes a painted GLB, an OBJ for Mixamo and a preview. cutout_ai/adopt --ai let rembg decide near-black regions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
22
cutout.py
22
cutout.py
@@ -88,6 +88,28 @@ def cutout(path, holes=False, share=HOLE_SHARE):
|
||||
return Image.fromarray(out.astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
_SESSION = None
|
||||
|
||||
|
||||
def cutout_ai(path, model="isnet-general-use"):
|
||||
"""Wie cutout(), aber fast schwarze Stellen entscheidet ein Freistell-Modell (rembg):
|
||||
dunkle Haut, dunkler Stoff oder Haare bleiben Figur, eingeschlossene Lücken (zwischen Arm
|
||||
und Körper, im Lasso) werden Hintergrund. Helle Bildteile behalten die genaue Kante."""
|
||||
global _SESSION
|
||||
from rembg import new_session, remove
|
||||
if _SESSION is None:
|
||||
_SESSION = new_session(model)
|
||||
base = cutout(path) # Kante und helle Teile
|
||||
arr = np.asarray(base).copy()
|
||||
rgb = arr[:, :, :3].astype(np.int16)
|
||||
brightness = rgb.max(axis=2)
|
||||
mask = np.asarray(remove(Image.open(path).convert("RGB"), session=_SESSION, only_mask=True).convert("L"))
|
||||
dark = ndimage.binary_dilation(brightness <= BLACK_THRESHOLD + 25, iterations=2)
|
||||
# dunkle Bereiche: Deckkraft vom Modell (weich), sonst unverändert
|
||||
arr[:, :, 3] = np.where(dark, mask, arr[:, :, 3]).astype(np.uint8)
|
||||
return Image.fromarray(arr, "RGBA")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Flags apart from the name, so `--holes` works on either side of it.
|
||||
flags = {arg for arg in sys.argv[1:] if arg.startswith("--")}
|
||||
|
||||
Reference in New Issue
Block a user