Astridkraft commited on
Commit
effc865
·
verified ·
1 Parent(s): 73f9907

Update sam_module.py

Browse files
Files changed (1) hide show
  1. sam_module.py +8 -7
sam_module.py CHANGED
@@ -301,17 +301,17 @@ def create_sam_mask(self, image, bbox_coords, mode):
301
  print("🎯 MODUS: FOCUS_CHANGE (OPTIMIERT)")
302
  print("-" * 60)
303
 
304
- # Bild für SAM vorbereiten
305
  image_np = np.array(image.convert("RGB"))
306
 
307
- # NUR EINE BBOX UND NUR MITTELPUNKT (kein Gesichtspunkt)
308
  input_boxes = [[[x1, y1, x2, y2]]]
309
 
310
  # Nur Mittelpunkt als positiver Prompt
311
  center_x = (x1 + x2) // 2
312
  center_y = (y1 + y2) // 2
313
- input_points = [[[[center_x, center_y]]]] # NUR EIN PUNKT
314
- input_labels = [[[1]]] # Positiver Prompt
315
 
316
  print(f" 🎯 SAM-Prompt: BBox [{x1},{y1},{x2},{y2}]")
317
  print(f" 👁️ Punkt: Nur Mitte ({center_x},{center_y})")
@@ -334,6 +334,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
334
  print(f" Anzahl der Vorhersagemasken: {outputs.pred_masks.shape[2]}")
335
 
336
  num_masks = outputs.pred_masks.shape[2]
 
337
 
338
  # Sammlung aller Masken in all_masks
339
  all_masks = []
@@ -348,7 +349,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
348
  ).squeeze()
349
 
350
  mask_np = resized_mask.sigmoid().cpu().numpy()
351
- all_masks.append(mask_np)
352
 
353
 
354
  # BBox-Information für Heuristik
@@ -359,7 +360,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
359
  best_mask_idx = 0
360
  best_score = -1
361
 
362
- # Alle 3 Masken analysieren (OHNE sie alle zu skalieren!)
363
  for i in range(num_masks):
364
  # Maske in Original-SAM-Größe (256x256) analysieren
365
  mask_256 = outputs.pred_masks[:, :, i, :, :]
@@ -386,7 +387,7 @@ def create_sam_mask(self, image, bbox_coords, mode):
386
  if np.sum(mask_binary) == 0:
387
  continue
388
 
389
- # Heuristik-Berechnung (wie bisher)
390
  mask_area_pixels = np.sum(mask_binary)
391
 
392
  # BBox-Überlappung
 
301
  print("🎯 MODUS: FOCUS_CHANGE (OPTIMIERT)")
302
  print("-" * 60)
303
 
304
+ # Konvertierung O-Bild in NumPy-Array für SAM
305
  image_np = np.array(image.convert("RGB"))
306
 
307
+ # Packt die BBox-Koordinaten in eine 3D-Liste
308
  input_boxes = [[[x1, y1, x2, y2]]]
309
 
310
  # Nur Mittelpunkt als positiver Prompt
311
  center_x = (x1 + x2) // 2
312
  center_y = (y1 + y2) // 2
313
+ input_points = [[[[center_x, center_y]]]] # NUR EIN PUNKT in 4D-Liste
314
+ input_labels = [[[1]]] # Markiert Punkt als Positiver Prompt also der Bereich muß segmentiert werden
315
 
316
  print(f" 🎯 SAM-Prompt: BBox [{x1},{y1},{x2},{y2}]")
317
  print(f" 👁️ Punkt: Nur Mitte ({center_x},{center_y})")
 
334
  print(f" Anzahl der Vorhersagemasken: {outputs.pred_masks.shape[2]}")
335
 
336
  num_masks = outputs.pred_masks.shape[2]
337
+
338
 
339
  # Sammlung aller Masken in all_masks
340
  all_masks = []
 
349
  ).squeeze()
350
 
351
  mask_np = resized_mask.sigmoid().cpu().numpy()
352
+ all_masks.append(mask_np) #fügt die aktuelle Maske der Liste all_masks hinzu
353
 
354
 
355
  # BBox-Information für Heuristik
 
360
  best_mask_idx = 0
361
  best_score = -1
362
 
363
+ # Alle 3 Masken analysieren
364
  for i in range(num_masks):
365
  # Maske in Original-SAM-Größe (256x256) analysieren
366
  mask_256 = outputs.pred_masks[:, :, i, :, :]
 
387
  if np.sum(mask_binary) == 0:
388
  continue
389
 
390
+ # Heuristik-Berechnung
391
  mask_area_pixels = np.sum(mask_binary)
392
 
393
  # BBox-Überlappung