Cursor Agent commited on
Commit
3fb53a0
·
1 Parent(s): a904d03

Enhance ball rings with neon glow effect (additive blending)

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -969,6 +969,7 @@ def compose_frame(state: AppState, frame_idx: int, remove_bg: bool = False) -> I
969
 
970
  current_union_mask: np.ndarray | None = None
971
  focus_mask: np.ndarray | None = None
 
972
 
973
  for obj_id, mask in masks.items():
974
  if mask is None:
@@ -984,6 +985,8 @@ def compose_frame(state: AppState, frame_idx: int, remove_bg: bool = False) -> I
984
  if focus_mask is None:
985
  focus_mask = np.zeros_like(mask_np, dtype=np.float32)
986
  focus_mask = np.maximum(focus_mask, mask_np)
 
 
987
 
988
  ghost_mask = _build_ball_trail_mask(state, frame_idx)
989
  ring_result = _build_ball_ring_mask(state, frame_idx)
@@ -1006,11 +1009,8 @@ def compose_frame(state: AppState, frame_idx: int, remove_bg: bool = False) -> I
1006
  result_np = _apply_cutout_fx(state, frame_np, combined_mask)
1007
  out_img = Image.fromarray(result_np)
1008
  else:
1009
- overlay_masks = masks
1010
- if (ghost_mask is not None or ring_result is not None) and BALL_OBJECT_ID in masks:
1011
- overlay_masks = {oid: mask for oid, mask in masks.items() if oid != BALL_OBJECT_ID}
1012
- if overlay_masks:
1013
- out_img = overlay_masks_on_frame(out_img, overlay_masks, state.color_by_obj, alpha=0.65)
1014
  # Overlay feathered ball on top
1015
  if BALL_OBJECT_ID in masks:
1016
  ball_mask = masks[BALL_OBJECT_ID]
@@ -1044,7 +1044,12 @@ def compose_frame(state: AppState, frame_idx: int, remove_bg: bool = False) -> I
1044
  ring_presence = np.clip(ring_presence.astype(np.float32), 0.0, 1.0)
1045
  ring_color_map = np.clip(ring_color_map.astype(np.float32), 0.0, 1.0)
1046
  if current_union_mask is not None:
1047
- mask_keep = np.clip(1.0 - current_union_mask, 0.0, 1.0)
 
 
 
 
 
1048
  ring_presence = ring_presence * mask_keep
1049
  ring_color_map = ring_color_map * mask_keep[..., None]
1050
  if ring_presence.max() > FX_EPS and ring_color_map.max() > FX_EPS:
 
969
 
970
  current_union_mask: np.ndarray | None = None
971
  focus_mask: np.ndarray | None = None
972
+ ball_mask_main: np.ndarray | None = None
973
 
974
  for obj_id, mask in masks.items():
975
  if mask is None:
 
985
  if focus_mask is None:
986
  focus_mask = np.zeros_like(mask_np, dtype=np.float32)
987
  focus_mask = np.maximum(focus_mask, mask_np)
988
+ if obj_id == BALL_OBJECT_ID:
989
+ ball_mask_main = mask
990
 
991
  ghost_mask = _build_ball_trail_mask(state, frame_idx)
992
  ring_result = _build_ball_ring_mask(state, frame_idx)
 
1009
  result_np = _apply_cutout_fx(state, frame_np, combined_mask)
1010
  out_img = Image.fromarray(result_np)
1011
  else:
1012
+ if masks:
1013
+ out_img = overlay_masks_on_frame(out_img, masks, state.color_by_obj, alpha=0.65)
 
 
 
1014
  # Overlay feathered ball on top
1015
  if BALL_OBJECT_ID in masks:
1016
  ball_mask = masks[BALL_OBJECT_ID]
 
1044
  ring_presence = np.clip(ring_presence.astype(np.float32), 0.0, 1.0)
1045
  ring_color_map = np.clip(ring_color_map.astype(np.float32), 0.0, 1.0)
1046
  if current_union_mask is not None:
1047
+ if ball_mask_main is not None:
1048
+ ball_np = np.clip(ball_mask_main.astype(np.float32), 0.0, 1.0)
1049
+ mask_block = np.maximum(current_union_mask - ball_np, 0.0)
1050
+ else:
1051
+ mask_block = current_union_mask
1052
+ mask_keep = np.clip(1.0 - mask_block, 0.0, 1.0)
1053
  ring_presence = ring_presence * mask_keep
1054
  ring_color_map = ring_color_map * mask_keep[..., None]
1055
  if ring_presence.max() > FX_EPS and ring_color_map.max() > FX_EPS: