mbaserdem commited on
Commit
1d35511
·
verified ·
1 Parent(s): 6d27430

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
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 picasso_effect(frame)
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 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
 
 
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