Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
color_ranges = [
|
| 6 |
([100, 150, 0], [140, 255, 255]), # Blue range
|
|
@@ -70,7 +71,7 @@ def apply_filter(filter_type, input_image=None):
|
|
| 70 |
elif filter_type == "Mehmet":
|
| 71 |
return apply_multiple_color_filters(frame)
|
| 72 |
elif filter_type == "Picasso":
|
| 73 |
-
return
|
| 74 |
|
| 75 |
|
| 76 |
|
|
@@ -92,32 +93,32 @@ def apply_multiple_color_filters(image):
|
|
| 92 |
filtered_image = cv2.bitwise_and(image, image, mask=combined_mask)
|
| 93 |
return filtered_image
|
| 94 |
|
| 95 |
-
def
|
| 96 |
-
#
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
|
| 123 |
|
|
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
color_ranges = [
|
| 7 |
([100, 150, 0], [140, 255, 255]), # Blue range
|
|
|
|
| 71 |
elif filter_type == "Mehmet":
|
| 72 |
return apply_multiple_color_filters(frame)
|
| 73 |
elif filter_type == "Picasso":
|
| 74 |
+
return split_and_shuffle_image(frame)
|
| 75 |
|
| 76 |
|
| 77 |
|
|
|
|
| 93 |
filtered_image = cv2.bitwise_and(image, image, mask=combined_mask)
|
| 94 |
return filtered_image
|
| 95 |
|
| 96 |
+
def split_and_shuffle_image(image):
|
| 97 |
+
# Determine the height and width of each piece
|
| 98 |
+
h, w, _ = image.shape
|
| 99 |
+
h_split, w_split = h // 3, w // 3
|
| 100 |
+
|
| 101 |
+
# Split the image into 9 pieces
|
| 102 |
+
pieces = []
|
| 103 |
+
for i in range(3):
|
| 104 |
+
for j in range(3):
|
| 105 |
+
piece = image[i * h_split:(i + 1) * h_split, j * w_split:(j + 1) * w_split]
|
| 106 |
+
pieces.append(piece)
|
| 107 |
+
|
| 108 |
+
# Shuffle the pieces
|
| 109 |
+
np.random.shuffle(pieces)
|
| 110 |
+
|
| 111 |
+
# Reconstruct the shuffled image
|
| 112 |
+
shuffled_image = np.zeros_like(image)
|
| 113 |
+
idx = 0
|
| 114 |
+
for i in range(3):
|
| 115 |
+
for j in range(3):
|
| 116 |
+
shuffled_image[i * h_split:(i + 1) * h_split, j * w_split:(j + 1) * w_split] = pieces[idx]
|
| 117 |
+
idx += 1
|
| 118 |
+
|
| 119 |
+
return shuffled_image
|
| 120 |
+
|
| 121 |
+
|
| 122 |
|
| 123 |
|
| 124 |
|