mbaserdem commited on
Commit
d72365f
·
verified ·
1 Parent(s): 0fcde95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -16
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 == "Mehmet":
72
- return apply_multiple_color_filters(frame)
73
  elif filter_type == "Picasso":
74
  return split_and_shuffle_image(frame)
75
 
76
 
77
 
78
 
79
- def apply_multiple_color_filters(image):
80
- hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
 
 
81
 
82
- # Initialize a mask with zeros (black)
83
- combined_mask = np.zeros(hsv_image.shape[:2], dtype="uint8")
84
 
85
- # Loop through each color range and create masks
86
- for (lower_color, upper_color) in color_ranges:
87
- lower_bound = np.array(lower_color)
88
- upper_bound = np.array(upper_color)
89
- mask = cv2.inRange(hsv_image, lower_bound, upper_bound)
90
- combined_mask = cv2.bitwise_or(combined_mask, mask)
 
91
 
92
- # Apply the combined mask to the image
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
@@ -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","Mehmet"],
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