-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_enhance_contrast_gray.py
40 lines (35 loc) · 1 KB
/
pre_enhance_contrast_gray.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
#%%
import fnmatch, os, re
import glob
import math
import cv2
import numpy as np
import operator
from matplotlib import pyplot as plt
point = '.'
extension = 'jpg'
point_extension = '.'+ extension
tag = '_contrast_gray'
#%%
def preview(image):
plt.imshow(image,cmap='gray'), plt.axis("off")
plt.show()
#%%
def insensitive_glob(pattern):
def either(c):
return '[%s%s]' % (c.lower(), c.upper()) if c.isalpha() else c
return glob.glob(''.join(map(either, pattern)))
def main():
for filename in insensitive_glob(os.path.join('data','*','*.{}').format(extension)):
if '.DS_Store' in filename or '_' in filename:
continue
image = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
image_enhanced = cv2.equalizeHist(image)
# preview(image_enhanced)
(name, ext) = filename.split('.')
status = cv2.imwrite(name+tag+point_extension,image_enhanced)
#%%
if __name__ == '__main__':
main()
print('Enhance constrast Gray photos successful!!!')
#%%