-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCooling effect.py
More file actions
45 lines (33 loc) · 1.46 KB
/
Cooling effect.py
File metadata and controls
45 lines (33 loc) · 1.46 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
import cv2
import numpy as np
from scipy.interpolate import UnivariateSpline
img = cv2.imread("cat.png")
#Cooling effect
class CoolingFilter():
def __init__(self):
"""Initialize look-up table for curve filter"""
# create look-up tables for increasing and decreasing a channel
self.incr_ch_lut = self._create_LUT_8UC1([0, 64, 128, 192, 256],
[0, 70, 140, 210, 256])
self.decr_ch_lut = self._create_LUT_8UC1([0, 64, 128, 192, 256],
[0, 30, 80, 120, 192])
def render(self, img_rgb):
c_r, c_g, c_b = cv2.split(img_rgb)
c_r = cv2.LUT(c_r, self.incr_ch_lut).astype(np.uint8)
c_b = cv2.LUT(c_b, self.decr_ch_lut).astype(np.uint8)
img_rgb = cv2.merge((c_r, c_g, c_b))
c_h, c_s, c_v = cv2.split(cv2.cvtColor(img_rgb, cv2.COLOR_RGB2HSV))
c_s = cv2.LUT(c_s, self.incr_ch_lut).astype(np.uint8)
return cv2.cvtColor(cv2.merge((c_h, c_s, c_v)), cv2.COLOR_HSV2RGB)
def _create_LUT_8UC1(self, x, y):
"""Creates a look-up table using scipy's spline interpolation"""
spl = UnivariateSpline(x, y)
return spl(range(256))
print('Cooling Effect Applied.')
y = CoolingFilter()
Cool = y.render(img)
#comparing original vs resized
cv2.imshow('ORIGINAL',img)
cv2.imshow('Cooling effect',Cool)
cv2.waitKey(0)
cv2.destroyAllWindows()