Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,30 +68,46 @@ def apply_filter(filter_type, input_image=None):
|
|
| 68 |
return apply_sepia_filter(frame)
|
| 69 |
elif filter_type == "Sonbahar":
|
| 70 |
return apply_fall_filter(frame)
|
| 71 |
-
elif filter_type == "
|
| 72 |
-
return
|
| 73 |
elif filter_type == "Picasso":
|
| 74 |
return split_and_shuffle_image(frame)
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
-
def
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
-
#
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def split_and_shuffle_image(image):
|
| 97 |
# Determine the height and width of each piece
|
|
@@ -129,7 +145,7 @@ with gr.Blocks() as demo:
|
|
| 129 |
# Filtre seçenekleri
|
| 130 |
filter_type = gr.Dropdown(
|
| 131 |
label="Filtre Seçin",
|
| 132 |
-
choices=["Picasso","Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar","
|
| 133 |
value="Picasso"
|
| 134 |
)
|
| 135 |
|
|
|
|
| 68 |
return apply_sepia_filter(frame)
|
| 69 |
elif filter_type == "Sonbahar":
|
| 70 |
return apply_fall_filter(frame)
|
| 71 |
+
elif filter_type == "Porcelain":
|
| 72 |
+
return apply_porcelain_splatter_effect(frame)
|
| 73 |
elif filter_type == "Picasso":
|
| 74 |
return split_and_shuffle_image(frame)
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
+
def apply_porcelain_splatter_effect(image):
|
| 80 |
+
# Assume 'image' is an RGB NumPy array
|
| 81 |
+
# Get image dimensions
|
| 82 |
+
height, width, _ = image.shape
|
| 83 |
|
| 84 |
+
# Create a blank layer for the porcelain splatter effect
|
| 85 |
+
splatter_layer = np.zeros((height, width, 3), dtype=np.uint8)
|
| 86 |
|
| 87 |
+
# Define colors for splatter pattern
|
| 88 |
+
colors = [
|
| 89 |
+
(255, 140, 0), # orange
|
| 90 |
+
(0, 128, 0), # green
|
| 91 |
+
(0, 0, 255), # red
|
| 92 |
+
(70, 130, 180) # matte blue
|
| 93 |
+
]
|
| 94 |
|
| 95 |
+
# Add random splatter patterns
|
| 96 |
+
for _ in range(1000):
|
| 97 |
+
# Random position for splatter
|
| 98 |
+
x, y = np.random.randint(0, width), np.random.randint(0, height)
|
| 99 |
+
# Random color from defined palette
|
| 100 |
+
color = colors[np.random.randint(0, len(colors))]
|
| 101 |
+
# Random radius for splatter
|
| 102 |
+
radius = np.random.randint(1, 10)
|
| 103 |
+
# Draw a small circle on the splatter layer
|
| 104 |
+
cv2.circle(splatter_layer, (x, y), radius, color, -1)
|
| 105 |
+
|
| 106 |
+
# Blend the splatter layer with the original image to get the porcelain effect
|
| 107 |
+
alpha = 0.4 # transparency for splatter layer
|
| 108 |
+
porcelain_image = cv2.addWeighted(image, 1 - alpha, splatter_layer, alpha, 0)
|
| 109 |
+
|
| 110 |
+
return porcelain_image
|
| 111 |
|
| 112 |
def split_and_shuffle_image(image):
|
| 113 |
# Determine the height and width of each piece
|
|
|
|
| 145 |
# Filtre seçenekleri
|
| 146 |
filter_type = gr.Dropdown(
|
| 147 |
label="Filtre Seçin",
|
| 148 |
+
choices=["Picasso","Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar","Porcelain"],
|
| 149 |
value="Picasso"
|
| 150 |
)
|
| 151 |
|