Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,6 +69,8 @@ def apply_filter(filter_type, input_image=None):
|
|
| 69 |
return apply_fall_filter(frame)
|
| 70 |
elif filter_type == "Mehmet":
|
| 71 |
return apply_multiple_color_filters(frame)
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
|
|
@@ -90,6 +92,33 @@ def apply_multiple_color_filters(image):
|
|
| 90 |
filtered_image = cv2.bitwise_and(image, image, mask=combined_mask)
|
| 91 |
return filtered_image
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
# Gradio arayüzü
|
|
@@ -99,8 +128,8 @@ with gr.Blocks() as demo:
|
|
| 99 |
# Filtre seçenekleri
|
| 100 |
filter_type = gr.Dropdown(
|
| 101 |
label="Filtre Seçin",
|
| 102 |
-
choices=["Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar","Mehmet"],
|
| 103 |
-
value="
|
| 104 |
)
|
| 105 |
|
| 106 |
# Görüntü yükleme alanı
|
|
|
|
| 69 |
return apply_fall_filter(frame)
|
| 70 |
elif filter_type == "Mehmet":
|
| 71 |
return apply_multiple_color_filters(frame)
|
| 72 |
+
elif filter_type == "Picasso":
|
| 73 |
+
return picasso_effect(frame)
|
| 74 |
|
| 75 |
|
| 76 |
|
|
|
|
| 92 |
filtered_image = cv2.bitwise_and(image, image, mask=combined_mask)
|
| 93 |
return filtered_image
|
| 94 |
|
| 95 |
+
def picasso_effect(image_array):
|
| 96 |
+
# Convert the RGB array to an image
|
| 97 |
+
image = cv2.cvtColor(image_array, cv2.COLOR_RGB2BGR)
|
| 98 |
+
|
| 99 |
+
# Apply bilateral filter to smooth the image while keeping edges sharp
|
| 100 |
+
filtered_image = cv2.bilateralFilter(image, d=9, sigmaColor=75, sigmaSpace=75)
|
| 101 |
+
|
| 102 |
+
# Convert to grayscale
|
| 103 |
+
gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY)
|
| 104 |
+
|
| 105 |
+
# Apply edge detection
|
| 106 |
+
edges = cv2.Canny(gray_image, threshold1=100, threshold2=200)
|
| 107 |
+
|
| 108 |
+
# Dilate the edges to make them more pronounced
|
| 109 |
+
dilated_edges = cv2.dilate(edges, kernel=np.ones((3, 3), np.uint8), iterations=1)
|
| 110 |
+
|
| 111 |
+
# Invert the edges
|
| 112 |
+
inverted_edges = cv2.bitwise_not(dilated_edges)
|
| 113 |
+
|
| 114 |
+
# Convert edges to 3 channels
|
| 115 |
+
edges_colored = cv2.cvtColor(inverted_edges, cv2.COLOR_GRAY2BGR)
|
| 116 |
+
|
| 117 |
+
# Blend the edges with the original image
|
| 118 |
+
abstract_image = cv2.addWeighted(filtered_image, 0.7, edges_colored, 0.3, 0)
|
| 119 |
+
|
| 120 |
+
return abstract_image
|
| 121 |
+
|
| 122 |
|
| 123 |
|
| 124 |
# Gradio arayüzü
|
|
|
|
| 128 |
# Filtre seçenekleri
|
| 129 |
filter_type = gr.Dropdown(
|
| 130 |
label="Filtre Seçin",
|
| 131 |
+
choices=["Picasso","Gaussian Blur", "Sharpen", "Edge Detection", "Invert", "Brightness", "Grayscale", "Sepia", "Sonbahar","Mehmet"],
|
| 132 |
+
value="Picasso"
|
| 133 |
)
|
| 134 |
|
| 135 |
# Görüntü yükleme alanı
|