-
Notifications
You must be signed in to change notification settings - Fork 3
/
image_enhancement.py
56 lines (43 loc) · 1.38 KB
/
image_enhancement.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
''' Image Enhancement OpenCV '''
#--------------------------------
# Date : 18-06-2020
# Project : Image Enhancement OpenCV
# Category : Image Processing
# Company : weblineindia
# Department : AI/ML
#--------------------------------
import os
import cv2
from scipy import ndimage
PATH = 'Dataset/'
RESULTS = 'Results/'
"""
# Removes noise and imporves image quality.
"""
def enhanceImage(path):
for filename in os.listdir(path):
try:
image = cv2.imread(path+filename)
if image is not None:
# Convert image to gray scale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Non-Linear filter for noise removal
deNoised = ndimage.median_filter(gray_image, 3)
#Histogram Equalizer
#High pass filter for improving the contrast of the image
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
highPass = clahe.apply(deNoised)
#Gamma Transformation
#Prevent bleaching or darkening of images
gamma = highPass/255.0
gammaFilter = cv2.pow(gamma,1.5)
gammaFilter = gammaFilter * 255
cv2.imwrite(RESULTS+filename,gammaFilter)
except:
print('Image not found')
print("--------IMAGE ENHANCEMENT TECHNIQUE----------")
print("---------------------------------------------")
print("--------INITIALIZED IMAGE PROCESSING---------")
# Enhance Image Quality
enhanceImage(path=PATH)
print("--------IMAGE PROCESSING COMPLETED-----------")