Spaces:
Sleeping
Sleeping
Upload landmarkdiff/masking.py with huggingface_hub
Browse files- landmarkdiff/masking.py +21 -4
landmarkdiff/masking.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
"""Surgical mask
|
| 2 |
|
| 3 |
-
Procedural (not SAM2)
|
| 4 |
-
Feathered
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
from __future__ import annotations
|
|
@@ -64,7 +65,23 @@ def generate_surgical_mask(
|
|
| 64 |
clinical_flags: "ClinicalFlags | None" = None,
|
| 65 |
image: np.ndarray | None = None,
|
| 66 |
) -> np.ndarray:
|
| 67 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
if procedure not in MASK_CONFIG:
|
| 69 |
raise ValueError(f"Unknown procedure: {procedure}. Choose from {list(MASK_CONFIG)}")
|
| 70 |
|
|
|
|
| 1 |
+
"""Surgical mask generation with morphological dilation and Gaussian feathering.
|
| 2 |
|
| 3 |
+
Procedural masks (not SAM2) — deterministic, no model dependency.
|
| 4 |
+
Feathered boundaries prevent visible seams in ControlNet inpainting.
|
| 5 |
+
Supports clinical edge cases (vitiligo preservation, keloid softening).
|
| 6 |
"""
|
| 7 |
|
| 8 |
from __future__ import annotations
|
|
|
|
| 65 |
clinical_flags: "ClinicalFlags | None" = None,
|
| 66 |
image: np.ndarray | None = None,
|
| 67 |
) -> np.ndarray:
|
| 68 |
+
"""Generate a feathered surgical mask for a procedure.
|
| 69 |
+
|
| 70 |
+
Pipeline:
|
| 71 |
+
1. Create convex hull from procedure-specific landmarks
|
| 72 |
+
2. Morphological dilation by N pixels
|
| 73 |
+
3. Gaussian feathering for smooth alpha gradient
|
| 74 |
+
4. Add Perlin-style noise at boundary to prevent visible seams
|
| 75 |
+
|
| 76 |
+
Args:
|
| 77 |
+
face: Extracted facial landmarks.
|
| 78 |
+
procedure: Procedure name.
|
| 79 |
+
width: Mask width.
|
| 80 |
+
height: Mask height.
|
| 81 |
+
|
| 82 |
+
Returns:
|
| 83 |
+
Float32 mask array [0.0-1.0] with feathered boundaries.
|
| 84 |
+
"""
|
| 85 |
if procedure not in MASK_CONFIG:
|
| 86 |
raise ValueError(f"Unknown procedure: {procedure}. Choose from {list(MASK_CONFIG)}")
|
| 87 |
|