-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimg_prcs.py
62 lines (47 loc) · 1.33 KB
/
img_prcs.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
56
57
58
59
60
61
62
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from PIL import Image,ImageEnhance, ImageFilter
from pytesseract import image_to_string
import os
'''
def average(pixel):
return np.average(pixel)
'''
def image_enhance(img):
#set dpi to 600,600
image = Image.open(img)
dir = os.getcwd()+"/enhanced_test"
os.chdir(dir)
#image.save('image_600.jpg',dpi=(600,600))
#image enhacement
#image = Image.open('image_600.jpg')
image = image.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Sharpness(image)
factor = 2.0
image = enhancer.enhance(factor)
#grey scale
coloriser = ImageEnhance.Color(image)
factor = 0.0
image = coloriser.enhance(factor)
#contrast setting
coloriser = ImageEnhance.Contrast(image)
image.save('image_enhanced.jpg')
code = image_to_string(Image.open('image_enhanced.jpg'))
return code
'''
#Grey scale conversion
image = misc.imread('test2-600.jpg')
print image.shape
grey = np.zeros((image.shape[0], image.shape[1])) # init 2D numpy array
# get row number
for rownum in range(len(image)):
for colnum in range(len(image[rownum])):
grey[rownum][colnum] = average(image[rownum][colnum])
plt.imshow(grey, cmap = cm.Greys_r)
plt.show()
misc.imsave('test2-grey.jpg',grey)
code = image_to_string(Image.open('test2-grey.jpg'))
print code
'''