Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 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):
|