ArunLouis commited on
Commit
522777b
·
verified ·
1 Parent(s): 5752949

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -45,19 +45,20 @@ def apply_depth_aware_blur(
45
 
46
  blurred_image = np.copy(np.array(original_image))
47
 
48
- if foreground_blur > 0:
 
49
  blurred_image = np.where(
50
  (foreground_mask[..., None] == 255),
51
  cv2.GaussianBlur(blurred_image, (foreground_blur, foreground_blur), 10),
52
  blurred_image,
53
  )
54
- if midground_blur > 0:
55
  blurred_image = np.where(
56
  (midground_mask[..., None] == 255),
57
  cv2.GaussianBlur(blurred_image, (midground_blur, midground_blur), 8),
58
  blurred_image,
59
  )
60
- if background_blur > 0:
61
  blurred_image = np.where(
62
  (background_mask[..., None] == 255),
63
  cv2.GaussianBlur(blurred_image, (background_blur, background_blur), 20),
@@ -71,8 +72,8 @@ def apply_depth_aware_blur(
71
  example_image = np.zeros((512, 512, 3), dtype=np.uint8) # Placeholder for an image
72
  example_inputs = [
73
  example_image,
74
- 0, # foreground_blur
75
- 0, # midground_blur
76
  35, # background_blur (default)
77
  0.2, # foreground_threshold (default)
78
  0.2, # midground_lower (default)
@@ -84,9 +85,9 @@ iface = gr.Interface(
84
  fn=apply_depth_aware_blur,
85
  inputs=[
86
  gr.Image(label="Input Image"),
87
- gr.Slider(0, 51, step=2, label="Foreground Blur Kernel Size"),
88
- gr.Slider(0, 51, step=2, label="Midground Blur Kernel Size"),
89
- gr.Slider(0, 51, step=2, label="Background Blur Kernel Size"),
90
  gr.Slider(0, 1, label="Foreground Threshold"),
91
  gr.Slider(0, 1, label="Midground Lower Threshold"),
92
  gr.Slider(0, 1, label="Midground Upper Threshold"),
 
45
 
46
  blurred_image = np.copy(np.array(original_image))
47
 
48
+ # Apply blur, ensuring kernel size is valid
49
+ if foreground_blur > 0 and foreground_blur % 2 == 1:
50
  blurred_image = np.where(
51
  (foreground_mask[..., None] == 255),
52
  cv2.GaussianBlur(blurred_image, (foreground_blur, foreground_blur), 10),
53
  blurred_image,
54
  )
55
+ if midground_blur > 0 and midground_blur % 2 == 1:
56
  blurred_image = np.where(
57
  (midground_mask[..., None] == 255),
58
  cv2.GaussianBlur(blurred_image, (midground_blur, midground_blur), 8),
59
  blurred_image,
60
  )
61
+ if background_blur > 0 and background_blur % 2 == 1:
62
  blurred_image = np.where(
63
  (background_mask[..., None] == 255),
64
  cv2.GaussianBlur(blurred_image, (background_blur, background_blur), 20),
 
72
  example_image = np.zeros((512, 512, 3), dtype=np.uint8) # Placeholder for an image
73
  example_inputs = [
74
  example_image,
75
+ 15, # foreground_blur
76
+ 7, # midground_blur
77
  35, # background_blur (default)
78
  0.2, # foreground_threshold (default)
79
  0.2, # midground_lower (default)
 
85
  fn=apply_depth_aware_blur,
86
  inputs=[
87
  gr.Image(label="Input Image"),
88
+ gr.Slider(1, 51, step=2, label="Foreground Blur Kernel Size"),
89
+ gr.Slider(1, 51, step=2, label="Midground Blur Kernel Size"),
90
+ gr.Slider(1, 51, step=2, label="Background Blur Kernel Size"),
91
  gr.Slider(0, 1, label="Foreground Threshold"),
92
  gr.Slider(0, 1, label="Midground Lower Threshold"),
93
  gr.Slider(0, 1, label="Midground Upper Threshold"),