LeafCat79 commited on
Commit
ab1e231
·
verified ·
1 Parent(s): 4a5615c

Reject asymmetric radial overhead sprites

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -2478,14 +2478,34 @@ def has_implausibly_thin_foreground_subject(content: bytes, spec: AssetSpec) ->
2478
  )
2479
 
2480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2481
  def has_front_view_like_top_down_silhouette(content: bytes, spec: AssetSpec) -> bool:
2482
  """Reject silhouettes that contradict a requested overhead body footprint.
2483
 
2484
  Alpha geometry cannot prove camera perspective. It can, however, fail closed
2485
  when a normalized, canvas-filling silhouette contradicts explicit user terms:
2486
- compact humanoids cannot remain upright portraits; radial bodies must not be
2487
- taller than wide; and explicitly wide vehicles must present a wide footprint.
2488
- Narrow props remain exempt.
2489
  """
2490
  if spec.camera != "top_down" or spec.composition not in {"single_subject", "icon", "animation_frame"}:
2491
  return False
@@ -2503,14 +2523,28 @@ def has_front_view_like_top_down_silhouette(content: bytes, spec: AssetSpec) ->
2503
  if height_ratio < 0.72:
2504
  return False
2505
 
 
2506
  geometry = infer_top_down_subject_geometry(spec)
2507
  if geometry == "humanoid" and aspect >= 1.10:
2508
  return True
2509
 
2510
- if geometry == "radial" and aspect >= 1.02:
2511
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2512
 
2513
- description = f"{spec.description} {spec.prompt}"
2514
  explicitly_wide_vehicle = geometry == "vehicle" and contains_any_term(
2515
  description,
2516
  ("wide", "four-wheel", "four wheel", "six-wheel", "six wheel", "tracked"),
 
2478
  )
2479
 
2480
 
2481
+ def foreground_rotational_symmetry(content: bytes) -> float:
2482
+ """Measure 180-degree alpha-mask balance inside the material foreground bounds."""
2483
+ image = Image.open(io.BytesIO(content)).convert("RGBA")
2484
+ bbox = material_foreground_bbox_from_image(image)
2485
+ if bbox is None:
2486
+ return 0.0
2487
+ x0, y0, x1, y1 = bbox
2488
+ alpha = image.getchannel("A").crop((x0, y0, x1 + 1, y1 + 1))
2489
+ foreground = [value >= 64 for value in alpha.tobytes()]
2490
+ if not any(foreground):
2491
+ return 0.0
2492
+ rotated = reversed(foreground)
2493
+ intersection = 0
2494
+ union = 0
2495
+ for original, opposite in zip(foreground, rotated):
2496
+ intersection += original and opposite
2497
+ union += original or opposite
2498
+ return intersection / max(1, union)
2499
+
2500
+
2501
  def has_front_view_like_top_down_silhouette(content: bytes, spec: AssetSpec) -> bool:
2502
  """Reject silhouettes that contradict a requested overhead body footprint.
2503
 
2504
  Alpha geometry cannot prove camera perspective. It can, however, fail closed
2505
  when a normalized, canvas-filling silhouette contradicts explicit user terms:
2506
+ compact humanoids cannot remain upright portraits; explicitly radial bodies
2507
+ must be broad and rotationally balanced; and explicitly wide vehicles must
2508
+ present a wide footprint. Narrow props remain exempt.
2509
  """
2510
  if spec.camera != "top_down" or spec.composition not in {"single_subject", "icon", "animation_frame"}:
2511
  return False
 
2523
  if height_ratio < 0.72:
2524
  return False
2525
 
2526
+ description = f"{spec.description} {spec.prompt}"
2527
  geometry = infer_top_down_subject_geometry(spec)
2528
  if geometry == "humanoid" and aspect >= 1.10:
2529
  return True
2530
 
2531
+ if geometry == "radial":
2532
+ if aspect >= 1.02:
2533
+ return True
2534
+ explicitly_balanced_radial = contains_any_term(
2535
+ description,
2536
+ (
2537
+ "radial",
2538
+ "six-legged",
2539
+ "six legged",
2540
+ "splayed evenly",
2541
+ "evenly splayed",
2542
+ "limbs radiate",
2543
+ ),
2544
+ )
2545
+ if explicitly_balanced_radial and foreground_rotational_symmetry(content) < 0.40:
2546
+ return True
2547
 
 
2548
  explicitly_wide_vehicle = geometry == "vehicle" and contains_any_term(
2549
  description,
2550
  ("wide", "four-wheel", "four wheel", "six-wheel", "six wheel", "tracked"),