-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter_image.py
28 lines (22 loc) · 990 Bytes
/
filter_image.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
from PIL import ImageEnhance, Image
import cv2
def filter_brightness_for_image(open_cv_image, param_enchance):
img_pil = Image.fromarray(cv2.cvtColor(open_cv_image, cv2.COLOR_BGR2RGB))
converter = ImageEnhance.Brightness(img_pil)
img = converter.enhance(param_enchance)
return img
def filter_image(np_array_image):
'''np_array_image - numpy.dnarray'''
# for color images
#equ = cv2.equalizeHist(cv2.cvtColor(np_array_image, cv2.COLOR_BGR2GRAY))
equ = cv2.equalizeHist(np_array_image)
im_pil = Image.fromarray(cv2.cvtColor(equ, cv2.COLOR_BGR2RGB))
return im_pil
def filter_image2(np_array_image):
# for color images
#equ = cv2.equalizeHist(cv2.cvtColor(np_array_image, cv2.COLOR_BGR2GRAY))
equ = cv2.equalizeHist(np_array_image)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
cl1 = clahe.apply(equ)
im_pil = Image.fromarray(cv2.cvtColor(cl1, cv2.COLOR_BGR2RGB))
return im_pil