forked from dsabarinathan/OpenDocument
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
63 lines (39 loc) · 1.92 KB
/
utils.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
63
# -*- coding: utf-8 -*-
"""
@author: sabari
"""
import cv2
from skimage.filters import threshold_sauvola
import numpy as np
class preprocessing():
def sauvola_thresholding(grayImage_,window_size=15):
""""
Sauvola thresholds are local thresholding techniques that are
useful for images where the background is not uniform, especially for text recognition
grayImage--- Input image should be in 2-Dimension Gray Scale format
window_size --- It represents the filter window size
"""
thresh_sauvolavalue = threshold_sauvola(grayImage_, window_size=window_size)
thresholdImage_=(grayImage_>thresh_sauvolavalue)
return thresholdImage_
def remove_Lines(binaryImage_,horz_size=12,vert_size=15):
"""
Removing the horizontal and vertical lines in the image
binaryImage_--- Image should be in binray format
horz_size -- It represents the Minimum size of horizantal line need to be removed from the image
vert_size -- It represents the Minimum size of vertical line need to be removed from the image
"""
horz_size=round(binaryImage_.shape[0]*0.075)
vert_size=round(binaryImage_.shape[1]*0.09)
horizontal_kernel=np.ones((1,horz_size),np.uint8)
vertical_kernel=np.ones((vert_size,1),np.uint8)
hz_closing = cv2.morphologyEx(binaryImage_, cv2.MORPH_CLOSE, horizontal_kernel)
ver_closing = cv2.morphologyEx(binaryImage_, cv2.MORPH_CLOSE, vertical_kernel)
Lines = hz_closing&ver_closing
LinesRemoved= binaryImage_| (~Lines)
return np.uint8(LinesRemoved)
"""
thresholdImage=preprocessing.sauvola_thresholding(grayImage)
removeLines=preprocessing.remove_Lines(np.uint8(thresholdImage))
"""
## remove lines ###