-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunwithfilters.py
More file actions
71 lines (63 loc) · 2.55 KB
/
Funwithfilters.py
File metadata and controls
71 lines (63 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import cv2
import numpy as np
def apply_filter(image_path, filter_type):
"""Apply the specified color filter to the image."""
# Create a copy of the image to avoid modifying the original
filtered_image = image.copy()
if filter_type == 'red_tint':
# Remove blue and green channels for red tint
filtered_image[:, :, 1] = 0 # Green channel to 0
filtered_image[:, :, 0] = 0 # Blue channel to 0
elif filter_type == "blue_tint":
# Remove red and green channels for blue tint
filtered_image[:, :, 1] = 0 # Green channel to 0
filtered_image[:, :, 2] = 0 # Red channel to 0
elif filter_type == "green_tint":
# Remove blue and red channels for blue tint
filtered_image[:, :, 0] = 0 # Blue channel to 0
filtered_image[:, :, 2] = 0 # Red channel to 0
elif filter_type == "increased_red":
# Increase the intensity of the red channel
filtered_image[:, :, 2] = cv2.add(filtered_image[:, :, 2], 50) # Increase red channel
elif filter_type == "decreased blue":
# Decrease the intensity of the blue channel
filtered_image[:, :, 0] = cv2.subtract(filtered_image[:, :, 0], 50) # Decrease blue channel
return filtered_image
# Load the image
image_path = 'Anothermustang.avif' # Provide your image path
image = cv2.imread(image_path)
if image is None:
print("Error: Image not found.")
else:
filter_type = "original" # Default filter type
print("Press the following keys to apply filters:")
print("r: Red Tint")
print("b: Blue Tint")
print("g: Green Tint")
print("i: Increased Red Intensity")
print("d: Decreased Blue Intensity")
print("q: Quit")
while True:
# Apply the selected filter
filtered_image = apply_color_filter(image, filter_type)
# Display the filtered image
cv2.imshow('Filtered Image', filtered_image)
# Wait for a key press
key = cv2.waitKey(0) & 0xFF
# Map key presses to filters
if key == ord('r'):
filter_type = "red_tint"
elif key == ord('b'):
filter_type = "blue_tint"
elif key == ord('g'):
filter_type = "green_tint"
elif key == ord('i'):
filter_type = "increased_red"
elif key == ord('d'):
filter_type = "decreased_blue"
elif key == ord("q"):
print("Exiting...")
break
else:
print("Invalid key pressed. Please use keys 'r', 'b', 'g', 'i', 'd', or 'q'.")
cv2.destroyAllWindows()