Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 168 |
-
"""
|
| 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 sanatsal_filtreler(image, filter_type):
|
|
| 175 |
hsv[:,:,1] = hsv[:,:,1]*1.5
|
| 176 |
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
| 177 |
|
| 178 |
-
elif filter_type == "
|
| 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 == "
|
| 186 |
-
#
|
| 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 |
-
#
|
| 194 |
hsv = cv2.cvtColor(cartoon, cv2.COLOR_BGR2HSV)
|
| 195 |
-
hsv[:,:,1] = hsv[:,:,1]*1.4 #
|
| 196 |
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
| 197 |
|
| 198 |
-
def
|
| 199 |
-
"""
|
| 200 |
-
if filter_type == "
|
| 201 |
-
#
|
| 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 |
-
#
|
| 209 |
hsv = cv2.cvtColor(autumn, cv2.COLOR_BGR2HSV)
|
| 210 |
-
hsv[:,:,0] = hsv[:,:,0]*0.8 #
|
| 211 |
-
hsv[:,:,1] = hsv[:,:,1]*1.2 #
|
| 212 |
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
| 213 |
|
| 214 |
-
elif filter_type == "
|
| 215 |
-
#
|
| 216 |
-
#
|
| 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 |
-
#
|
| 224 |
h, w = image.shape[:2]
|
| 225 |
kernel = np.zeros((h, w))
|
| 226 |
center = (h//2, w//2)
|
|
@@ -231,16 +231,16 @@ def atmosferik_filtreler(image, filter_type):
|
|
| 231 |
kernel = np.dstack([kernel]*3)
|
| 232 |
return cv2.multiply(sepia, kernel).astype(np.uint8)
|
| 233 |
|
| 234 |
-
elif filter_type == "
|
| 235 |
-
#
|
| 236 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
| 237 |
-
#
|
| 238 |
hsv[:,:,2] = cv2.convertScaleAbs(hsv[:,:,2], alpha=1.2, beta=30)
|
| 239 |
-
#
|
| 240 |
return cv2.convertScaleAbs(cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), alpha=1.1, beta=0)
|
| 241 |
|
| 242 |
-
def
|
| 243 |
-
"""
|
| 244 |
if image is None:
|
| 245 |
return None
|
| 246 |
|
|
|
|
| 164 |
axis=random.randint(0, 1))
|
| 165 |
return glitch
|
| 166 |
|
| 167 |
+
def artistic_filters(image, filter_type):
|
| 168 |
+
"""Applies 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 |
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":
|
| 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 # saturation increase
|
| 196 |
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
| 197 |
|
| 198 |
+
def atmospheric_filters(image, filter_type):
|
| 199 |
+
"""atmospheric filters"""
|
| 200 |
+
if filter_type == "Autumn":
|
| 201 |
+
# Genhanced 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 # Shift to 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 |
+
# Darkening effect in corners
|
| 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 == "Brightness Enhancement":
|
| 235 |
+
# Improved brightness boost
|
| 236 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
| 237 |
+
# Increase brightness
|
| 238 |
hsv[:,:,2] = cv2.convertScaleAbs(hsv[:,:,2], alpha=1.2, beta=30)
|
| 239 |
+
# Also 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 |
+
"""Main image processing function"""
|
| 244 |
if image is None:
|
| 245 |
return None
|
| 246 |
|