Update app.py
Browse files
app.py
CHANGED
|
@@ -364,10 +364,10 @@ def enhanced_composite_with_sam(original_image, inpaint_result, original_mask,
|
|
| 364 |
|
| 365 |
# Verwende gespeicherte BBox aus scaled_image_and_mask_together()
|
| 366 |
if 'scaled_bbox' in padding_info and padding_info['scaled_bbox'] is not None:
|
| 367 |
-
bbox_in_512 = padding_info['scaled_bbox'] # ← WICHTIG: Verwende die gespeicherte
|
| 368 |
print(f"✅ Verwende gespeicherte BBox: {bbox_in_512}")
|
| 369 |
else:
|
| 370 |
-
#BBox-Koordinaten korrekt transformieren
|
| 371 |
#Die BBox-Koordinaten müssen vom Originalbild nach 512x512 transformiert werden
|
| 372 |
bbox_scaled = (
|
| 373 |
int(bbox_coords[0] * scale_factor),
|
|
@@ -383,12 +383,14 @@ def enhanced_composite_with_sam(original_image, inpaint_result, original_mask,
|
|
| 383 |
bbox_scaled[3] + y_offset
|
| 384 |
)
|
| 385 |
|
|
|
|
|
|
|
| 386 |
if bbox_in_512[2] > bbox_in_512[0] and bbox_in_512[3] > bbox_in_512[1]:
|
| 387 |
-
# Bearbeiteten Bereich aus dem 512×512-Ergebnis ausschneiden
|
| 388 |
edited_region = inpaint_result.crop(bbox_in_512)
|
| 389 |
|
| 390 |
|
| 391 |
-
#
|
| 392 |
original_bbox_size = (bbox_coords[2] - bbox_coords[0],
|
| 393 |
bbox_coords[3] - bbox_coords[1])
|
| 394 |
edited_region_fullsize = edited_region.resize(
|
|
@@ -396,8 +398,10 @@ def enhanced_composite_with_sam(original_image, inpaint_result, original_mask,
|
|
| 396 |
Image.Resampling.LANCZOS
|
| 397 |
)
|
| 398 |
|
| 399 |
-
# SAM-Maske
|
|
|
|
| 400 |
mask_cropped = original_mask.crop(bbox_coords)
|
|
|
|
| 401 |
soft_mask = mask_cropped.filter(ImageFilter.GaussianBlur(3))
|
| 402 |
|
| 403 |
# Alpha-Compositing mit präziser SAM-Maske
|
|
|
|
| 364 |
|
| 365 |
# Verwende gespeicherte BBox aus scaled_image_and_mask_together()
|
| 366 |
if 'scaled_bbox' in padding_info and padding_info['scaled_bbox'] is not None:
|
| 367 |
+
bbox_in_512 = padding_info['scaled_bbox'] # ← WICHTIG: Verwende die gespeicherte skalierte BBox
|
| 368 |
print(f"✅ Verwende gespeicherte BBox: {bbox_in_512}")
|
| 369 |
else:
|
| 370 |
+
#BBox-Koordinaten korrekt transformieren
|
| 371 |
#Die BBox-Koordinaten müssen vom Originalbild nach 512x512 transformiert werden
|
| 372 |
bbox_scaled = (
|
| 373 |
int(bbox_coords[0] * scale_factor),
|
|
|
|
| 383 |
bbox_scaled[3] + y_offset
|
| 384 |
)
|
| 385 |
|
| 386 |
+
# Die BBox-Koordinaten sind durch 2 Punkte gegeben: oben links (x,y)-unten rechts (x,y)
|
| 387 |
+
# Prüfung: hat BBox gültige Koordinaten
|
| 388 |
if bbox_in_512[2] > bbox_in_512[0] and bbox_in_512[3] > bbox_in_512[1]:
|
| 389 |
+
# Bearbeiteten Bereich aus dem 512×512-Ergebnis ausschneiden in Größe der 512x512-skalierten BBox
|
| 390 |
edited_region = inpaint_result.crop(bbox_in_512)
|
| 391 |
|
| 392 |
|
| 393 |
+
# Damit wird der 512er BBox-Inhalt auf Originalgröße-BBox hochskaliert
|
| 394 |
original_bbox_size = (bbox_coords[2] - bbox_coords[0],
|
| 395 |
bbox_coords[3] - bbox_coords[1])
|
| 396 |
edited_region_fullsize = edited_region.resize(
|
|
|
|
| 398 |
Image.Resampling.LANCZOS
|
| 399 |
)
|
| 400 |
|
| 401 |
+
# SAM-Maske= original_mask in Originalgröße (also Smartphone: 4032x3024)Aus dieser Maske muß nun der
|
| 402 |
+
# Original BBox-Bereich ausgeschnitten werden und
|
| 403 |
mask_cropped = original_mask.crop(bbox_coords)
|
| 404 |
+
# der Randbereich muß für Übergänge weich gezeichnet werden
|
| 405 |
soft_mask = mask_cropped.filter(ImageFilter.GaussianBlur(3))
|
| 406 |
|
| 407 |
# Alpha-Compositing mit präziser SAM-Maske
|