Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ def basic_filter(image, filter_type):
|
|
15 |
[0.393, 0.769, 0.189]
|
16 |
])
|
17 |
return cv2.transform(image, sepia_filter)
|
18 |
-
elif filter_type == "
|
19 |
# Improved X-ray effect
|
20 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
21 |
inverted = cv2.bitwise_not(gray)
|
@@ -26,12 +26,12 @@ def basic_filter(image, filter_type):
|
|
26 |
kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
|
27 |
sharpened = cv2.filter2D(enhanced, -1, kernel)
|
28 |
return cv2.cvtColor(sharpened, cv2.COLOR_GRAY2BGR)
|
29 |
-
elif filter_type == "
|
30 |
return cv2.GaussianBlur(image, (15, 15), 0)
|
31 |
|
32 |
def classic_filter(image, filter_type):
|
33 |
"""Classical display filters"""
|
34 |
-
if filter_type == "
|
35 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
36 |
inverted = cv2.bitwise_not(gray)
|
37 |
blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
|
@@ -109,7 +109,7 @@ def special_effects(image, filter_type):
|
|
109 |
|
110 |
elif filter_type == "Time Stamp":
|
111 |
output = image.copy()
|
112 |
-
timestamp = datetime.now().strftime("%
|
113 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
114 |
cv2.putText(output, timestamp, (10, 30), font, 1, (255, 255, 255), 2)
|
115 |
return output
|
@@ -202,7 +202,7 @@ def atmospheric_filter(image, filter_type):
|
|
202 |
# Increase the contrast slightly
|
203 |
return cv2.convertScaleAbs(cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), alpha=1.1, beta=0)
|
204 |
|
205 |
-
def
|
206 |
"""Function of main image processing"""
|
207 |
if image is None:
|
208 |
return None
|
@@ -210,21 +210,21 @@ def goruntu_isleme(image, filter_type):
|
|
210 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
211 |
|
212 |
# Process by filter categories
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
artistic_filters_listesi = ["Pop Art", "Oil Paint", "Cartoon"]
|
218 |
-
atmospheric_filters_list = ["Autumn", "Nostalgia", "
|
219 |
|
220 |
if filter_type in basic_filter_list:
|
221 |
output = basic_filter(image, filter_type)
|
222 |
elif filter_type in classic_filter_list:
|
223 |
output = classic_filters(image, filter_type)
|
224 |
-
elif filter_type in
|
225 |
-
output =
|
226 |
-
elif filter_type in
|
227 |
-
output =
|
228 |
elif filter_type in artistic_filters_list:
|
229 |
output = artistic_filters (image, filter_type)
|
230 |
elif filter_type in atmospheric_filters_list:
|
@@ -236,9 +236,8 @@ def goruntu_isleme(image, filter_type):
|
|
236 |
|
237 |
# Gradio interface
|
238 |
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
239 |
-
gr.Markdown("
|
240 |
-
|
241 |
-
|
242 |
with gr.Row():
|
243 |
with gr.Column():
|
244 |
image_input = gr.Image(type="numpy", label="📸 Upload Photos")
|
@@ -246,28 +245,17 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
|
246 |
filter_type = gr.Radio(
|
247 |
[
|
248 |
# Basic Filters
|
249 |
-
"Grey Toning", "Sepia", "
|
250 |
-
#
|
251 |
-
"
|
252 |
-
# Creative Filters
|
253 |
-
"Picles Art," "Mosaic Effect," "Rainbow," "Night Vision,"
|
254 |
-
# Special Effects
|
255 |
-
"Matrix Effect," "Window Effect", "Time Stamp," "Glitch Effect,"
|
256 |
-
# Artistic Filters
|
257 |
-
"Pop Art", "Oil Paint", "Cartoon",
|
258 |
-
#Atmospheric Filters
|
259 |
-
"Autumn", "Nostalgia", "Increasing Shiny"# Basic Filters
|
260 |
-
"Grey Toning", "Sepia", "Röntgen", "Frain",
|
261 |
-
#classic_filters_list
|
262 |
-
"Karakalem Effect," "Cutify", "Emovation", "Bens Perception,"
|
263 |
# Creative Filters
|
264 |
-
"
|
265 |
# Special Effects
|
266 |
-
"Matrix Effect,
|
267 |
# Artistic Filters
|
268 |
"Pop Art", "Oil Paint", "Cartoon",
|
269 |
#Atmospheric Filters
|
270 |
-
"Autumn", "Nostalgia", "
|
271 |
],
|
272 |
label="🎭 Select Filter",
|
273 |
info="Choose the magic effect you want"
|
@@ -284,35 +272,37 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
|
284 |
#### 📊 Basic Filters
|
285 |
- **Grey Toning**: Turns the image into a classic style in black and white tones
|
286 |
- **Sepia**: Adds warm brown tones that give the photo an old photo vibe
|
287 |
-
- **
|
288 |
-
- **
|
289 |
|
290 |
#### Classic Filters List
|
291 |
-
- **
|
292 |
-
- **
|
293 |
- **Emboss**: Adds embossing and depth effect to the image
|
294 |
- **Bulk Detection: Emphasizes edge lines in the image
|
295 |
|
296 |
-
####
|
297 |
-
- **
|
298 |
- **Mosaic Effect**: Divids the photo into small pieces of mosaics
|
299 |
- **Rainbow**: Adds colored rainbow effects to the image
|
300 |
- **Night Vision***: Simulates the night vision device effect
|
301 |
|
302 |
-
####
|
303 |
- **Matrix Effect**: Matrix movie effect
|
304 |
-
- **
|
305 |
- **Time Stamp***: Adds the date and time of taking the photo on it gives a nostalgic atmosphere
|
306 |
- **Glitch Effect***: Adding digital distortions, adds a retro style error effect to the photo
|
307 |
|
308 |
-
####
|
309 |
- **Pop Art**: With vivid and contrasted colors, Andy Warhol-style creates iconic pop-art effect
|
310 |
- **Oil Paint***: Simulates brush strokes, giving the image the appearance of oil painting
|
311 |
- **Texture Effect***: Adding surface texture to the image gives a touching depth and a vial of artwork
|
|
|
|
|
312 |
""")
|
313 |
|
314 |
submit_button.click(
|
315 |
-
|
316 |
inputs=[image_input, filter_type],
|
317 |
outputs=image_output
|
318 |
)
|
|
|
15 |
[0.393, 0.769, 0.189]
|
16 |
])
|
17 |
return cv2.transform(image, sepia_filter)
|
18 |
+
elif filter_type == "X-ray":
|
19 |
# Improved X-ray effect
|
20 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
21 |
inverted = cv2.bitwise_not(gray)
|
|
|
26 |
kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
|
27 |
sharpened = cv2.filter2D(enhanced, -1, kernel)
|
28 |
return cv2.cvtColor(sharpened, cv2.COLOR_GRAY2BGR)
|
29 |
+
elif filter_type == "Blur":
|
30 |
return cv2.GaussianBlur(image, (15, 15), 0)
|
31 |
|
32 |
def classic_filter(image, filter_type):
|
33 |
"""Classical display filters"""
|
34 |
+
if filter_type == "Charcoal Effect":
|
35 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
36 |
inverted = cv2.bitwise_not(gray)
|
37 |
blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
|
|
|
109 |
|
110 |
elif filter_type == "Time Stamp":
|
111 |
output = image.copy()
|
112 |
+
timestamp = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
|
113 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
114 |
cv2.putText(output, timestamp, (10, 30), font, 1, (255, 255, 255), 2)
|
115 |
return output
|
|
|
202 |
# Increase the contrast slightly
|
203 |
return cv2.convertScaleAbs(cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), alpha=1.1, beta=0)
|
204 |
|
205 |
+
def image_processing(image, filter_type):
|
206 |
"""Function of main image processing"""
|
207 |
if image is None:
|
208 |
return None
|
|
|
210 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
211 |
|
212 |
# Process by filter categories
|
213 |
+
basic_filter_list = ["Grey Toning", "Sepia", "X-ray", "Blur"]
|
214 |
+
Classic_filters_list = ["Charcoal Effect", "Sharpen", "Relief", "Edge Detection"]
|
215 |
+
creative_filters_list = ["Pixel Art", "Mosaic Effect", "Rainbow", "Night Vision"]
|
216 |
+
special_effects_list = ["Matrix Effect", "Wave Effect", "Time Stamp," "Glitch Effect"]
|
217 |
artistic_filters_listesi = ["Pop Art", "Oil Paint", "Cartoon"]
|
218 |
+
atmospheric_filters_list = ["Autumn", "Nostalgia", "Increase Brightness"]
|
219 |
|
220 |
if filter_type in basic_filter_list:
|
221 |
output = basic_filter(image, filter_type)
|
222 |
elif filter_type in classic_filter_list:
|
223 |
output = classic_filters(image, filter_type)
|
224 |
+
elif filter_type in creative_filter_list:
|
225 |
+
output = creative_filters(image, filter_type)
|
226 |
+
elif filter_type in special_effects_list:
|
227 |
+
output = special_effects(image, filter_type)
|
228 |
elif filter_type in artistic_filters_list:
|
229 |
output = artistic_filters (image, filter_type)
|
230 |
elif filter_type in atmospheric_filters_list:
|
|
|
236 |
|
237 |
# Gradio interface
|
238 |
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
239 |
+
gr.Markdown("Image Filtering Studio")
|
240 |
+
|
|
|
241 |
with gr.Row():
|
242 |
with gr.Column():
|
243 |
image_input = gr.Image(type="numpy", label="📸 Upload Photos")
|
|
|
245 |
filter_type = gr.Radio(
|
246 |
[
|
247 |
# Basic Filters
|
248 |
+
"Grey Toning", "Sepia", "X-ray", "Blur",
|
249 |
+
# Classic_filters_list
|
250 |
+
"Charcoal Effect", "Sharpen", "Relief", "Edge Detection",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
# Creative Filters
|
252 |
+
"Pixel Art", "Mosaic Effect", "Rainbow", "Night Vision",
|
253 |
# Special Effects
|
254 |
+
"Matrix Effect", "Wave Effect", "Time Stamp", "Glitch Effect",
|
255 |
# Artistic Filters
|
256 |
"Pop Art", "Oil Paint", "Cartoon",
|
257 |
#Atmospheric Filters
|
258 |
+
"Autumn", "Nostalgia", "Increasing Shiny"
|
259 |
],
|
260 |
label="🎭 Select Filter",
|
261 |
info="Choose the magic effect you want"
|
|
|
272 |
#### 📊 Basic Filters
|
273 |
- **Grey Toning**: Turns the image into a classic style in black and white tones
|
274 |
- **Sepia**: Adds warm brown tones that give the photo an old photo vibe
|
275 |
+
- **X-ray**: Creates the effect of an X-ray scan by adding backlighting to the image
|
276 |
+
- **Blur": It reduces details by creating a soft blur in the image.
|
277 |
|
278 |
#### Classic Filters List
|
279 |
+
- **Charcoal Effect**: It makes the image look like a charcoal drawing
|
280 |
+
- **Sharpen**: Highlights the details in the image
|
281 |
- **Emboss**: Adds embossing and depth effect to the image
|
282 |
- **Bulk Detection: Emphasizes edge lines in the image
|
283 |
|
284 |
+
#### Creative Filters
|
285 |
+
- **Pixel Art***: Dividing the image into small frames in retro pixel style
|
286 |
- **Mosaic Effect**: Divids the photo into small pieces of mosaics
|
287 |
- **Rainbow**: Adds colored rainbow effects to the image
|
288 |
- **Night Vision***: Simulates the night vision device effect
|
289 |
|
290 |
+
#### Special Effects
|
291 |
- **Matrix Effect**: Matrix movie effect
|
292 |
+
- **Wave Effect**: Adds a water wave-like twisted degradation to the image, creating a feeling of ripple
|
293 |
- **Time Stamp***: Adds the date and time of taking the photo on it gives a nostalgic atmosphere
|
294 |
- **Glitch Effect***: Adding digital distortions, adds a retro style error effect to the photo
|
295 |
|
296 |
+
#### Artistic Filters
|
297 |
- **Pop Art**: With vivid and contrasted colors, Andy Warhol-style creates iconic pop-art effect
|
298 |
- **Oil Paint***: Simulates brush strokes, giving the image the appearance of oil painting
|
299 |
- **Texture Effect***: Adding surface texture to the image gives a touching depth and a vial of artwork
|
300 |
+
|
301 |
+
|
302 |
""")
|
303 |
|
304 |
submit_button.click(
|
305 |
+
image_processing,
|
306 |
inputs=[image_input, filter_type],
|
307 |
outputs=image_output
|
308 |
)
|