DigiP-AI commited on
Commit
8043794
·
verified ·
1 Parent(s): 98104e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -164,8 +164,8 @@ def special_effects(image, filter_type):
164
  axis=random.randint(0, 1))
165
  return glitch
166
 
167
- def artistic_filter(image, filter_type):
168
- """Apply artistic image filters"""
169
  if filter_type == "Pop Art":
170
  img_small = cv2.resize(image, None, fx=0.5, fy=0.5)
171
  img_color = cv2.resize(img_small, (image.shape[1], image.shape[0]))
@@ -175,52 +175,52 @@ def artistic_filter(image, filter_type):
175
  hsv[:,:,1] = hsv[:,:,1]*1.5
176
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
177
 
178
- elif filter_type == "Oil Paint":
179
  ret = np.float32(image.copy())
180
  ret = cv2.bilateralFilter(ret, 9, 75, 75)
181
  ret = cv2.detailEnhance(ret, sigma_s=15, sigma_r=0.15)
182
  ret = cv2.edgePreservingFilter(ret, flags=1, sigma_s=60, sigma_r=0.4)
183
  return np.uint8(ret)
184
 
185
- elif filter_type == "Cartoon Film":
186
- # Improved cartoon effect
187
  color = image.copy()
188
  gray = cv2.cvtColor(color, cv2.COLOR_BGR2GRAY)
189
  gray = cv2.medianBlur(gray, 5)
190
  edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
191
  color = cv2.bilateralFilter(color, 9, 300, 300)
192
  cartoon = cv2.bitwise_and(color, color, mask=edges)
193
- # Increase color saturation
194
  hsv = cv2.cvtColor(cartoon, cv2.COLOR_BGR2HSV)
195
- hsv[:,:,1] = hsv[:,:,1]*1.4 # Increase in saturation
196
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
197
 
198
- def atmospheric_filter(image, filter_type):
199
- """Atmospheric Filters"""
200
- if filter_type == "Autumn":
201
- # Improved autumn effect
202
  autumn_filter = np.array([
203
  [0.393, 0.769, 0.189],
204
  [0.349, 0.686, 0.168],
205
  [0.272, 0.534, 0.131]
206
  ])
207
  autumn = cv2.transform(image, autumn_filter)
208
- # Increase color temperature
209
  hsv = cv2.cvtColor(autumn, cv2.COLOR_BGR2HSV)
210
- hsv[:,:,0] = hsv[:,:,0]*0.8 # Orange/yellow tones
211
- hsv[:,:,1] = hsv[:,:,1]*1.2 # Increase saturation
212
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
213
 
214
- elif filter_type == "Nostalgia":
215
- # Improved nostalgia effect
216
- # Reduce contrast and add yellowish tone
217
  image = cv2.convertScaleAbs(image, alpha=0.9, beta=10)
218
  sepia = cv2.transform(image, np.array([
219
  [0.393, 0.769, 0.189],
220
  [0.349, 0.686, 0.168],
221
  [0.272, 0.534, 0.131]
222
  ]))
223
- # Dimming effect in corners
224
  h, w = image.shape[:2]
225
  kernel = np.zeros((h, w))
226
  center = (h//2, w//2)
@@ -231,16 +231,16 @@ def atmospheric_filter(image, filter_type):
231
  kernel = np.dstack([kernel]*3)
232
  return cv2.multiply(sepia, kernel).astype(np.uint8)
233
 
234
- elif filter_type == "Increase Brightness":
235
- # Improved brightness enhancement
236
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
237
- # Increase brightness
238
  hsv[:,:,2] = cv2.convertScaleAbs(hsv[:,:,2], alpha=1.2, beta=30)
239
- # Increase the contrast slightly
240
  return cv2.convertScaleAbs(cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), alpha=1.1, beta=0)
241
 
242
- def image_processing(image, filter_type):
243
- """Function of main image processing"""
244
  if image is None:
245
  return None
246
 
 
164
  axis=random.randint(0, 1))
165
  return glitch
166
 
167
+ def sanatsal_filtreler(image, filter_type):
168
+ """Sanatsal görüntü filtrelerini uygular"""
169
  if filter_type == "Pop Art":
170
  img_small = cv2.resize(image, None, fx=0.5, fy=0.5)
171
  img_color = cv2.resize(img_small, (image.shape[1], image.shape[0]))
 
175
  hsv[:,:,1] = hsv[:,:,1]*1.5
176
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
177
 
178
+ elif filter_type == "Yağlı Boya":
179
  ret = np.float32(image.copy())
180
  ret = cv2.bilateralFilter(ret, 9, 75, 75)
181
  ret = cv2.detailEnhance(ret, sigma_s=15, sigma_r=0.15)
182
  ret = cv2.edgePreservingFilter(ret, flags=1, sigma_s=60, sigma_r=0.4)
183
  return np.uint8(ret)
184
 
185
+ elif filter_type == "Çizgi Film":
186
+ # Geliştirilmiş çizgi film efekti
187
  color = image.copy()
188
  gray = cv2.cvtColor(color, cv2.COLOR_BGR2GRAY)
189
  gray = cv2.medianBlur(gray, 5)
190
  edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
191
  color = cv2.bilateralFilter(color, 9, 300, 300)
192
  cartoon = cv2.bitwise_and(color, color, mask=edges)
193
+ # Renk doygunluğunu artır
194
  hsv = cv2.cvtColor(cartoon, cv2.COLOR_BGR2HSV)
195
+ hsv[:,:,1] = hsv[:,:,1]*1.4 # Doygunluk artışı
196
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
197
 
198
+ def atmosferik_filtreler(image, filter_type):
199
+ """Atmosferik filtreler"""
200
+ if filter_type == "Sonbahar":
201
+ # Geliştirilmiş sonbahar efekti
202
  autumn_filter = np.array([
203
  [0.393, 0.769, 0.189],
204
  [0.349, 0.686, 0.168],
205
  [0.272, 0.534, 0.131]
206
  ])
207
  autumn = cv2.transform(image, autumn_filter)
208
+ # Renk sıcaklığını artır
209
  hsv = cv2.cvtColor(autumn, cv2.COLOR_BGR2HSV)
210
+ hsv[:,:,0] = hsv[:,:,0]*0.8 # Turuncu/sarı tonlara kay
211
+ hsv[:,:,1] = hsv[:,:,1]*1.2 # Doygunluğu artır
212
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
213
 
214
+ elif filter_type == "Nostalji":
215
+ # Geliştirilmiş nostalji efekti
216
+ # Kontrastı azalt ve sarımsı ton ekle
217
  image = cv2.convertScaleAbs(image, alpha=0.9, beta=10)
218
  sepia = cv2.transform(image, np.array([
219
  [0.393, 0.769, 0.189],
220
  [0.349, 0.686, 0.168],
221
  [0.272, 0.534, 0.131]
222
  ]))
223
+ # Köşelerde karartma efekti
224
  h, w = image.shape[:2]
225
  kernel = np.zeros((h, w))
226
  center = (h//2, w//2)
 
231
  kernel = np.dstack([kernel]*3)
232
  return cv2.multiply(sepia, kernel).astype(np.uint8)
233
 
234
+ elif filter_type == "Parlaklık Artır":
235
+ # Geliştirilmiş parlaklık artırma
236
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
237
+ # Parlaklığı artır
238
  hsv[:,:,2] = cv2.convertScaleAbs(hsv[:,:,2], alpha=1.2, beta=30)
239
+ # Kontrastı da hafifçe artır
240
  return cv2.convertScaleAbs(cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), alpha=1.1, beta=0)
241
 
242
+ def goruntu_isleme(image, filter_type):
243
+ """Ana görüntü işleme fonksiyonu"""
244
  if image is None:
245
  return None
246