Cursor Agent commited on
Commit
64dd0b7
·
1 Parent(s): 0fcf462

Enhance ball rings with neon glow effect (additive blending)

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -577,6 +577,7 @@ class AppState:
577
  self.fx_ring_thickness: float = BALL_RING_THICKNESS_PX
578
  self.fx_ring_alpha: float = BALL_RING_ALPHA
579
  self.fx_ring_feather: float = BALL_RING_FEATHER_SIGMA
 
580
 
581
  def __repr__(self):
582
  return f"AppState(video_frames={self.video_frames}, inference_session={self.inference_session is not None}, model={self.model is not None}, processor={self.processor is not None}, device={self.device}, dtype={self.dtype}, video_fps={self.video_fps}, masks_by_frame={self.masks_by_frame}, color_by_obj={self.color_by_obj}, clicks_by_frame_obj={self.clicks_by_frame_obj}, boxes_by_frame_obj={self.boxes_by_frame_obj}, composited_frames={self.composited_frames}, current_frame_idx={self.current_frame_idx}, current_obj_id={self.current_obj_id}, current_label={self.current_label}, current_clear_old={self.current_clear_old}, current_prompt_type={self.current_prompt_type}, pending_box_start={self.pending_box_start}, pending_box_start_frame_idx={self.pending_box_start_frame_idx}, pending_box_start_obj_id={self.pending_box_start_obj_id}, is_switching_model={self.is_switching_model}, model_repo_key={self.model_repo_key}, model_repo_id={self.model_repo_id}, session_repo_id={self.session_repo_id})"
@@ -1108,6 +1109,7 @@ def _update_fx_controls(
1108
  ring_thickness: float,
1109
  ring_alpha: float,
1110
  ring_feather: float,
 
1111
  ) -> Image.Image:
1112
  if state is None:
1113
  return None
@@ -1129,6 +1131,7 @@ def _update_fx_controls(
1129
  state.fx_ring_thickness = max(1.0, float(ring_thickness))
1130
  state.fx_ring_alpha = max(0.0, float(ring_alpha))
1131
  state.fx_ring_feather = max(0.0, float(ring_feather))
 
1132
 
1133
  state.composited_frames.clear()
1134
  idx = int(getattr(state, "current_frame_idx", 0))
@@ -1285,8 +1288,9 @@ def _build_ball_ring_mask(state: AppState, frame_idx: int) -> np.ndarray | None:
1285
  max_val = float(ring_mask.max())
1286
  if max_val > FX_EPS:
1287
  ring_mask = ring_mask / max_val
1288
- if abs(BALL_RING_INTENSITY_GAMMA - 1.0) > 1e-6:
1289
- ring_mask = np.power(np.clip(ring_mask, 0.0, 1.0), BALL_RING_INTENSITY_GAMMA)
 
1290
  return np.clip(ring_mask, 0.0, 1.0)
1291
 
1292
 
@@ -2840,7 +2844,7 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
2840
  with gr.Column(scale=1):
2841
  ball_ring_chk = gr.Checkbox(
2842
  label="Ball rings (future)",
2843
- value=False,
2844
  info="Replace the ghost trail fill with magenta rings at future ball positions.",
2845
  )
2846
  with gr.Column(scale=1):
@@ -2954,7 +2958,15 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
2954
  minimum=0.0,
2955
  maximum=5.0,
2956
  step=0.1,
2957
- value=1.5, # Updated default from 0.75->1.5
 
 
 
 
 
 
 
 
2958
  )
2959
 
2960
  with gr.Row():
@@ -2978,6 +2990,7 @@ with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", the
2978
  ring_thickness,
2979
  ring_alpha,
2980
  ring_feather,
 
2981
  ]
2982
 
2983
  for comp in fx_inputs:
 
577
  self.fx_ring_thickness: float = BALL_RING_THICKNESS_PX
578
  self.fx_ring_alpha: float = BALL_RING_ALPHA
579
  self.fx_ring_feather: float = BALL_RING_FEATHER_SIGMA
580
+ self.fx_ring_gamma: float = BALL_RING_INTENSITY_GAMMA
581
 
582
  def __repr__(self):
583
  return f"AppState(video_frames={self.video_frames}, inference_session={self.inference_session is not None}, model={self.model is not None}, processor={self.processor is not None}, device={self.device}, dtype={self.dtype}, video_fps={self.video_fps}, masks_by_frame={self.masks_by_frame}, color_by_obj={self.color_by_obj}, clicks_by_frame_obj={self.clicks_by_frame_obj}, boxes_by_frame_obj={self.boxes_by_frame_obj}, composited_frames={self.composited_frames}, current_frame_idx={self.current_frame_idx}, current_obj_id={self.current_obj_id}, current_label={self.current_label}, current_clear_old={self.current_clear_old}, current_prompt_type={self.current_prompt_type}, pending_box_start={self.pending_box_start}, pending_box_start_frame_idx={self.pending_box_start_frame_idx}, pending_box_start_obj_id={self.pending_box_start_obj_id}, is_switching_model={self.is_switching_model}, model_repo_key={self.model_repo_key}, model_repo_id={self.model_repo_id}, session_repo_id={self.session_repo_id})"
 
1109
  ring_thickness: float,
1110
  ring_alpha: float,
1111
  ring_feather: float,
1112
+ ring_gamma: float,
1113
  ) -> Image.Image:
1114
  if state is None:
1115
  return None
 
1131
  state.fx_ring_thickness = max(1.0, float(ring_thickness))
1132
  state.fx_ring_alpha = max(0.0, float(ring_alpha))
1133
  state.fx_ring_feather = max(0.0, float(ring_feather))
1134
+ state.fx_ring_gamma = max(0.1, float(ring_gamma))
1135
 
1136
  state.composited_frames.clear()
1137
  idx = int(getattr(state, "current_frame_idx", 0))
 
1288
  max_val = float(ring_mask.max())
1289
  if max_val > FX_EPS:
1290
  ring_mask = ring_mask / max_val
1291
+ gamma_val = getattr(state, "fx_ring_gamma", BALL_RING_INTENSITY_GAMMA)
1292
+ if abs(gamma_val - 1.0) > 1e-6:
1293
+ ring_mask = np.power(np.clip(ring_mask, 0.0, 1.0), gamma_val)
1294
  return np.clip(ring_mask, 0.0, 1.0)
1295
 
1296
 
 
2844
  with gr.Column(scale=1):
2845
  ball_ring_chk = gr.Checkbox(
2846
  label="Ball rings (future)",
2847
+ value=True,
2848
  info="Replace the ghost trail fill with magenta rings at future ball positions.",
2849
  )
2850
  with gr.Column(scale=1):
 
2958
  minimum=0.0,
2959
  maximum=5.0,
2960
  step=0.1,
2961
+ value=1.5,
2962
+ )
2963
+ with gr.Column(scale=1):
2964
+ ring_gamma = gr.Slider(
2965
+ label="Ring Gamma (Contrast)",
2966
+ minimum=0.1,
2967
+ maximum=2.0,
2968
+ step=0.05,
2969
+ value=0.65, # Default gamma
2970
  )
2971
 
2972
  with gr.Row():
 
2990
  ring_thickness,
2991
  ring_alpha,
2992
  ring_feather,
2993
+ ring_gamma,
2994
  ]
2995
 
2996
  for comp in fx_inputs: