-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilters.py
More file actions
67 lines (56 loc) · 2.24 KB
/
filters.py
File metadata and controls
67 lines (56 loc) · 2.24 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
import numpy as np
import streamlit as st
import cv2
import copy
import imutils
import PIL
from PIL import Image
from scipy.interpolate import UnivariateSpline
# This Loads the Image
def load_image(img):
im = Image.open(img)
image = np.array(im)
return image
# GraySclaing the Image
def grayImage(image):
img = cv2.cvtColor(image, cv2.COLOR_RGBA2GRAY)
return img
# Getting the Edges of Image
def Edge(image):
return cv2.Canny(image, 100, 150)
# Blurring the Image
def gaussianBlur(image):
return cv2.GaussianBlur(image, (35, 35), 0)
# Spread Lookup for x and y
def spreadLookupTable(x, y):
spline = UnivariateSpline(x, y)
return spline(range(256))
# Applying Warm Filter to the Image
def warmImage(image):
increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256])
red_channel, green_channel, blue_channel = cv2.split(image)
red_channel = cv2.LUT(red_channel, increaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, decreaseLookupTable).astype(np.uint8)
return cv2.merge((red_channel, green_channel, blue_channel))
# Applying Cold Filter to the Image
def coldImage(image):
increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256])
red_channel, green_channel, blue_channel = cv2.split(image)
red_channel = cv2.LUT(red_channel, decreaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, increaseLookupTable).astype(np.uint8)
return cv2.merge((red_channel, green_channel, blue_channel))
def resize(image, left, top, right, bottom):
ima = image.crop((left, top, right, bottom))
resized = np.array(ima)
return resized
# Applying Sketch FIlter To Images
def divimg(x, y):
return cv2.divide(x, 255 - y, scale=256)
def Sketch(image):
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_invert = cv2.bitwise_not(img_gray)
img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
final_img = divimg(img_gray, img_smoothing)
return final_img