mbaserdem commited on
Commit
7a9f1f3
·
verified ·
1 Parent(s): af7422f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -2,6 +2,12 @@ import cv2
2
  import numpy as np
3
  import gradio as gr
4
 
 
 
 
 
 
 
5
  # Farklı filtre fonksiyonları
6
  def apply_gaussian_blur(frame):
7
  return cv2.GaussianBlur(frame, (15, 15), 0)
@@ -61,10 +67,35 @@ def apply_filter(filter_type, input_image=None):
61
  return apply_sepia_filter(frame)
62
  elif filter_type == "Sonbahar":
63
  return apply_fall_filter(frame)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  # Gradio arayüzü
66
  with gr.Blocks() as demo:
67
- gr.Markdown("# Web Kameradan Canlı Filtreleme")
68
 
69
  # Filtre seçenekleri
70
  filter_type = gr.Dropdown(
 
2
  import numpy as np
3
  import gradio as gr
4
 
5
+ color_ranges = [
6
+ ([100, 150, 0], [140, 255, 255]), # Blue range
7
+ ([35, 100, 100], [85, 255, 255]) # Green range
8
+ ]
9
+
10
+
11
  # Farklı filtre fonksiyonları
12
  def apply_gaussian_blur(frame):
13
  return cv2.GaussianBlur(frame, (15, 15), 0)
 
67
  return apply_sepia_filter(frame)
68
  elif filter_type == "Sonbahar":
69
  return apply_fall_filter(frame)
70
+ elif filter_type == "Mehmet":
71
+ return apply_multiple_color_filters(frame)
72
+
73
+
74
+
75
+
76
+ def apply_multiple_color_filters(image):
77
+ hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
78
+
79
+ # Initialize a mask with zeros (black)
80
+ combined_mask = np.zeros(hsv_image.shape[:2], dtype="uint8")
81
+
82
+ # Loop through each color range and create masks
83
+ for (lower_color, upper_color) in color_ranges:
84
+ lower_bound = np.array(lower_color)
85
+ upper_bound = np.array(upper_color)
86
+ mask = cv2.inRange(hsv_image, lower_bound, upper_bound)
87
+ combined_mask = cv2.bitwise_or(combined_mask, mask)
88
+
89
+ # Apply the combined mask to the image
90
+ filtered_image = cv2.bitwise_and(image, image, mask=combined_mask)
91
+ return filtered_image
92
+
93
+
94
+ apply_multiple_color_filters('path_to_your_image.jpg', color_ranges)
95
 
96
  # Gradio arayüzü
97
  with gr.Blocks() as demo:
98
+ gr.Markdown("# Image Proccessing Exercise 01 - Tech Istanbul")
99
 
100
  # Filtre seçenekleri
101
  filter_type = gr.Dropdown(