Text Location - Dual Processing

Processing the image

 1 from homeroberto.max_tree_alpha import MaxTreeAlpha
 2 from  homeroberto.rob_max_tree import SSIMIndex
 3 from homeroberto.max_tree_toolbox import evsFilter
 4 import numpy as np
 5 from morph import*
 6 from ia870 import iagshow
 7 
 8 img_path = find_attachment_file('homeroberto/rob_icpr_evs_simplification/sign2.png')
 9 img = adreadgray(img_path)
10 
11 n = 0.0050
12 
13 mxt = MaxTreeAlpha(img)
14 nleaves = (mxt.node_array[:,1] == 0).sum()
15 nnodes = mxt.node_array.shape[0]
16 l,c = img.shape
17 adshow(img,'Original Image: shape %d x %d, nnodes = %d, nleaves = %d'%(l,c,nnodes,nleaves))
18 
19 V = mxt.computeVolume()
20 ext = mxt.getExtinctionValues(V,"volume")
21 mxt = evsFilter(mxt,ext,int(n*nleaves))
22 nnodes = mxt.node_array.shape[0]
23 evs_img = mxt.getImage()
24 index_ = SSIMIndex(img,evs_img)
25 adshow(evs_img,'Filtered Image: n = %f,SSIM = %f, nnodes = %d'%(n,index_,nnodes))
26 
27 
28 sb = mxt.getSubBranches()
29 mxt.mmsT(sb, t =0.5)
30 
31 mms_img = mxt.getImage()
32 
33 
34 index = SSIMIndex(img,mms_img)
35 adshow(mms_img,'Filtered Image: SSIM = %f, nnodes = %d'%(index,len(sb)))
36 
37 
38 bin_img1 = np.zeros(img.shape,dtype = bool)
39 for node in [24, 25, 26, 28, 29, 30, 31, 33, 34, 36, 37, 38, 39, 40]:
40    bin_img1 = np.logical_or(bin_img1,mxt.recLevelComponent(node))
41 adshow(bin_img1, 'Binary Image')
42 
43 graph = mxt.generateCCGraph(s = (100,100), parent_scale = False, LR = True)
44 mmgraphviz(graph,title='Max-Tree after MMS')

Original Image: shape 384 x 512, nnodes = 13054, nleaves = 8249

Filtered Image: n = 0.005000,SSIM = 0.999756, nnodes = 2419

Filtered Image: SSIM = 0.920509, nnodes = 76

Binary Image

/media/_xsb/code/text_location_dual_processing/GRVIZ64654_001.png

Max-Tree after MMS

Processing the negative of the image

 1 n = 0.0050
 2 
 3 mxt = MaxTreeAlpha(mmneg(img))
 4 nleaves = (mxt.node_array[:,1] == 0).sum()
 5 nnodes = mxt.node_array.shape[0]
 6 l,c = img.shape
 7 adshow(img,'Original Image: shape %d x %d, nnodes = %d, nleaves = %d'%(l,c,nnodes,nleaves))
 8 
 9 V = mxt.computeVolume()
10 ext = mxt.getExtinctionValues(V,"volume")
11 mxt = evsFilter(mxt,ext,int(n*nleaves))
12 nnodes = mxt.node_array.shape[0]
13 evs_img = mmneg(mxt.getImage())
14 index_ = SSIMIndex(img,evs_img)
15 adshow(evs_img,'Filtered Image: n = %f,SSIM = %f, nnodes = %d'%(n,index_,nnodes))
16 
17 
18 sb = mxt.getSubBranches()
19 mxt.mmsT(sb, t =0.5)
20 
21 mms_img = mmneg(mxt.getImage())
22 
23 
24 index = SSIMIndex(img,mms_img)
25 adshow(mms_img,'Filtered Image: SSIM = %f, nnodes = %d'%(index,len(sb)))
26 
27 
28 bin_img2 = np.zeros(img.shape,dtype = bool)
29 for node in [18,19,20,21,23,24,26,27,30]:
30    bin_img2 = np.logical_or(bin_img2,mxt.recLevelComponent(node))
31 adshow(bin_img2, 'Binary Image')
32 
33 graph = mxt.generateCCGraph(s = (100,100), parent_scale = False, LR = True)
34 mmgraphviz(graph,title='Max-Tree after MMS')

Original Image: shape 384 x 512, nnodes = 13144, nleaves = 8416

Filtered Image: n = 0.005000,SSIM = 0.999824, nnodes = 1923

Filtered Image: SSIM = 0.961042, nnodes = 75

Binary Image

/media/_xsb/code/text_location_dual_processing/GRVIZ64654_002.png

Max-Tree after MMS

Text Location Result

1 adshow(iagshow(np.zeros(img.shape,dtype = 'uint8'),bin_img1,bin_img2), 'Result of the dual processing text location')

Result of the dual processing text location