-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLine_Segmenter_Utilities.py
62 lines (42 loc) · 938 Bytes
/
Line_Segmenter_Utilities.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
# coding: utf-8
# In[4]:
import scipy.io
import numpy as np
import matplotlib.pyplot as pyplot
from PIL import Image
import matplotlib.cm as cm
from pprint import pprint
import scipy.misc
import PIL
# In[5]:
image_arr=[]
def is_background(rowno,mat):
row,col=mat.shape
for i in range(0,col):
if mat[rowno][i]<0.9:
return False
return True
# In[7]:
def get_line_img(mat):
row,col=mat.shape
row_no=0
new_img=[]
for i in range(row):
if is_background(i,mat)==False:
new_img.append(mat[i])
else:
if len(new_img)!=0:
image_arr.append(new_img)
new_img=[]
# In[3]:
def process_image(ima):
img=scipy.misc.imread(ima)
#img=img[:,:,0]
img=img/255.0
return img
# In[12]:
def main(image_name):
img=process_image(image_name)
mat=img
get_line_img(mat)
return image_arr