-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpackage.py
167 lines (125 loc) · 4.57 KB
/
package.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import cv2
import numpy as np
def image_to_sketch():
image = cv2.imread("./assets/demo2.jpg")
grey_filter = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# cv2.imwrite("graysacle.jpg",grey_filter)
invert = cv2.bitwise_not(grey_filter)
# cv2.imwrite("invert.jpg",invert)
blur = cv2.GaussianBlur(invert,(21,21),0)
# cv2.imwrite("blur.jpg",blur)
invertedBlur = cv2.bitwise_not(blur)
# cv2.imwrite("invBlur.jpg",invertedBlur)
sketch = cv2.divide(grey_filter,invertedBlur,scale=256.0)
cv2.imwrite("sketch.jpg",sketch)
def image_to_oilPaint():
img = cv2.imread('./assets/demo2.jpg')
res = cv2.xphoto.oilPainting(img, 7, 1)
cv2.imwrite("oilPaint.jpg",res)
def image_to_colorSketch():
img = cv2.imread("./assets/demo2.jpg")
dst_gray,dst_color = cv2.pencilSketch(img, sigma_s=60, sigma_r=0.07, shade_factor=0.05)
cv2.imwrite("csketch.jpg",dst_color)
def image_to_darkSketch():
img = cv2.imread("./assets/demo2.jpg")
dst_gray,dst_color = cv2.pencilSketch(img, sigma_s=60, sigma_r=0.07, shade_factor=0.05)
cv2.imwrite("psketch.jpg",dst_gray)
def image_to_waterColor():
import cv2
img = cv2.imread('./assets/demo2.jpg')
res = cv2.stylization(img, sigma_s=60, sigma_r=0.6)
cv2.imwrite("waterColor.jpg",res)
def image_addition():
image1 = cv2.imread('./assets/demo4.jpg')
image2 = cv2.imread('./assets/demo3.jpg')
weightedSum = cv2.addWeighted(image1, 0.5, image2, 0.4, 0)
cv2.imwrite('weighted_image.jpg', weightedSum)
def image_subtraction():
image1 = cv2.imread('./assets/demo3.jpg')
image2 = cv2.imread('./assets/demo4.jpg')
subtract = cv2.subtract(image1, image2)
cv2.imwrite('subtract.jpg', subtract)
def bgr_hsv():
image = cv2.imread("./assets/demo2.jpg")
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
cv2.imwrite('hsv.jpg', hsv)
def smooth_image():
image = cv2.imread("./assets/demo4.jpg")
deionize = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 15)
cv2.imwrite('deionize.jpg', deionize)
def image_translation():
image = cv2.imread("./assets/demo4.jpg")
height, width = image.shape[:2]
quarter_height, quarter_width = height / 4, width / 4
T = np.float32([[1, 0, quarter_width], [0, 1, quarter_height]])
img_translation = cv2.warpAffine(image, T, (width, height))
cv2.imwrite('translation.jpg', img_translation)
def bilateral_filter():
image = cv2.imread("./assets/demo4.jpg")
b_filter = cv2.bilateralFilter(image,9,95,95)
cv2.imwrite('bilateralFilter.jpg', b_filter)
if __name__=="__main__":
# image_to_sketch()
# image_to_oilPaint()
# image_to_colorSketch()
# image_to_darkSketch()
# image_to_waterColor()
# image_addition()
# image_subtraction()
# bgr_hsv()
# smooth_image()
# image_translation()
# bilateral_filter()
print("Computer Graphics TA 1 ---- Group 1")
while(1):
print("Choices Available are : ")
print("1. Image to Sketch")
print("2. Image to Oil Paint")
print("3. Image to Color Sketch")
print("4. Image to Dark Sketch")
print("5. Image to Water Color")
print("6. Image Addition")
print("7. Image Subtraction")
print("8. Get Hue Saturation Value")
print("9. Smooth Image")
print("10. Image Translation")
print("11. Bilateral Image Filter")
print("0. Exit")
print("\n\n\n")
opt = int(input("Enter Your Choice"))
match opt:
case 1:
image_to_sketch()
print("1")
case 2:
image_to_oilPaint()
print("2")
case 3:
image_to_colorSketch()
print("3")
case 4:
image_to_darkSketch()
print("4")
case 5:
image_to_waterColor()
print("5")
case 6:
image_addition()
print("6")
case 7:
image_subtraction()
print("7")
case 8:
bgr_hsv()
print("8")
case 9:
smooth_image()
print("9")
case 10:
image_translation()
print("10")
case 11:
bilateral_filter()
print("11")
case _:
print("default")