Update controlnet_module.py
Browse files- controlnet_module.py +12 -4
controlnet_module.py
CHANGED
|
@@ -264,7 +264,7 @@ class ControlNetProcessor:
|
|
| 264 |
dynamic_threshold = max_val * 0.85
|
| 265 |
print(f" ✅ SAM ist sicher (max_val={max_val:.3f} >= 0.6)")
|
| 266 |
|
| 267 |
-
# Binärmaske erstellen
|
| 268 |
mask_array = (mask_np > dynamic_threshold).astype(np.uint8) * 255
|
| 269 |
|
| 270 |
# Fallback bei leerer Maske, der höchste Wert ist 0 also schwarz
|
|
@@ -342,8 +342,15 @@ class ControlNetProcessor:
|
|
| 342 |
|
| 343 |
working_mask = clean_mask
|
| 344 |
print(f" ✅ Konturenfilter - Größte Kontur behalten, {len(contours)-1} kleine entfernt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
-
|
| 347 |
|
| 348 |
# Gaussian-BLUR für weiche Kanten für Composition
|
| 349 |
working_mask = cv2.GaussianBlur(working_mask, (5, 5), 1.2)
|
|
@@ -379,6 +386,7 @@ class ControlNetProcessor:
|
|
| 379 |
# Zurück zu PIL Image
|
| 380 |
mask = Image.fromarray(final_mask).convert("L")
|
| 381 |
raw_mask = Image.fromarray(raw_mask_array).convert("L")
|
|
|
|
| 382 |
|
| 383 |
print("#" * 80)
|
| 384 |
print(f"✅ SAM 2 SEGMENTIERUNG ABGESCHLOSSEN")
|
|
@@ -386,10 +394,10 @@ class ControlNetProcessor:
|
|
| 386 |
print(f"🎛️ Verwendeter Modus: {mode}")
|
| 387 |
print("#" * 80)
|
| 388 |
|
| 389 |
-
return mask, raw_mask
|
| 390 |
|
| 391 |
# in mask steht die invertierte nachbearbeitete Maske, in raw_mask die Rohmaske.Wichtig: mask (SAM-Maske)
|
| 392 |
-
# muß immer in Originalgröße zurück!
|
| 393 |
|
| 394 |
# ============================================================
|
| 395 |
# BLOCK 2: FOCUS_CHANGE
|
|
|
|
| 264 |
dynamic_threshold = max_val * 0.85
|
| 265 |
print(f" ✅ SAM ist sicher (max_val={max_val:.3f} >= 0.6)")
|
| 266 |
|
| 267 |
+
# Binärmaske erstellen in Originalgröße
|
| 268 |
mask_array = (mask_np > dynamic_threshold).astype(np.uint8) * 255
|
| 269 |
|
| 270 |
# Fallback bei leerer Maske, der höchste Wert ist 0 also schwarz
|
|
|
|
| 342 |
|
| 343 |
working_mask = clean_mask
|
| 344 |
print(f" ✅ Konturenfilter - Größte Kontur behalten, {len(contours)-1} kleine entfernt")
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
#Inpaint darf nur eine schwarz/weiß Maske (Binärmaske 0,255) bekommen. Bei
|
| 348 |
+
#weichen/grauen Pixeln könnte Inpaint etwas anderes generieren. Die folgende
|
| 349 |
+
#Blur-Maske für Composition und UI-Anzeige
|
| 350 |
+
inpaint_binary_mask = working_mask.copy()
|
| 351 |
+
#Invertieren da SAM segmentierte Person/Gegenstand weiß ausgibt
|
| 352 |
+
inpaint_binary_mask = 255 - inpaint_binary_mask
|
| 353 |
|
|
|
|
| 354 |
|
| 355 |
# Gaussian-BLUR für weiche Kanten für Composition
|
| 356 |
working_mask = cv2.GaussianBlur(working_mask, (5, 5), 1.2)
|
|
|
|
| 386 |
# Zurück zu PIL Image
|
| 387 |
mask = Image.fromarray(final_mask).convert("L")
|
| 388 |
raw_mask = Image.fromarray(raw_mask_array).convert("L")
|
| 389 |
+
inpaint_binary_pil = Image.fromarray(inpaint_binary_mask).convert("L")
|
| 390 |
|
| 391 |
print("#" * 80)
|
| 392 |
print(f"✅ SAM 2 SEGMENTIERUNG ABGESCHLOSSEN")
|
|
|
|
| 394 |
print(f"🎛️ Verwendeter Modus: {mode}")
|
| 395 |
print("#" * 80)
|
| 396 |
|
| 397 |
+
return mask, raw_mask, inpaint_binary_pil
|
| 398 |
|
| 399 |
# in mask steht die invertierte nachbearbeitete Maske, in raw_mask die Rohmaske.Wichtig: mask (SAM-Maske)
|
| 400 |
+
# muß immer in Originalgröße zurück! in inpaint_binary_pil steht die harte, nachgearbeitete Binärmaske
|
| 401 |
|
| 402 |
# ============================================================
|
| 403 |
# BLOCK 2: FOCUS_CHANGE
|