gchallar commited on
Commit
4c98fbd
·
verified ·
1 Parent(s): 81824d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -26,12 +26,17 @@ except Exception as e:
26
 
27
  def apply_gaussian_blur_background(image, mask, radius):
28
  """Applies Gaussian blur to the background of the image."""
29
- blurred_background = image.filter(ImageFilter.GaussianBlur(radius=radius))
30
  img_array = np.array(image)
 
 
 
31
  blurred_array = np.array(blurred_background)
32
- foreground_mask = mask > 0
33
- foreground_mask_3d = np.stack([foreground_mask] * 3, axis=-1)
 
 
34
  final_image_array = np.where(foreground_mask_3d, img_array, blurred_array)
 
35
  return Image.fromarray(final_image_array.astype(np.uint8))
36
 
37
  def apply_depth_based_blur_background(image, mask, strength):
 
26
 
27
  def apply_gaussian_blur_background(image, mask, radius):
28
  """Applies Gaussian blur to the background of the image."""
 
29
  img_array = np.array(image)
30
+
31
+ # Apply Gaussian blur to the entire image
32
+ blurred_background = image.filter(ImageFilter.GaussianBlur(radius=radius))
33
  blurred_array = np.array(blurred_background)
34
+
35
+ # Ensure the mask is in the same size and format as the image
36
+ foreground_mask = np.array(mask) > 0
37
+ foreground_mask_3d = np.stack([foreground_mask] * 3, axis=-1) # Ensure it's 3 channels (RGB)
38
  final_image_array = np.where(foreground_mask_3d, img_array, blurred_array)
39
+
40
  return Image.fromarray(final_image_array.astype(np.uint8))
41
 
42
  def apply_depth_based_blur_background(image, mask, strength):