-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessoFiltroDeOrdem.py
More file actions
executable file
·78 lines (61 loc) · 2.09 KB
/
Copy pathprocessoFiltroDeOrdem.py
File metadata and controls
executable file
·78 lines (61 loc) · 2.09 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: cp1252 -*-
from dissertacaoFuncoes import *
# Sample for script execution:
# python processoFiltroDeOrdem.py '/home/user/folderWithImages/' '/home/user/folderWithImagesResult/' 6 1 10
theta = [
0, 23,
45, 68,
90, 113,
135, 158
]
def main(argv=None):
if argv is None:
argv = sys.argv
imPathRead = argv[1]
imPathSave = argv[2]
widthWindowRank = int(argv[3])
heightWindowRank = int(argv[4])
pRank = int(argv[5])
imSet = imageSet(idOS,imPathRead)
if len(argv) != 6:
print "Usage: " + argv[0] + " imPathRead imPathSave widthWindowRank heightWindowRank pRank"
return "Invalid number of parameters"
if os.access(imPathRead, os.F_OK) == False:
return "\"" + argv[1] + "\" does not exist"
if os.access(imPathSave, os.F_OK) == False:
return "\"" + argv[2] + "\" does not exist"
if os.access(imPathRead, os.R_OK) == False:
return "Unable to open \"" + sys.argv[1] + "\""
if os.access(imPathSave, os.R_OK) == False:
return "Unable to open \"" + sys.argv[2] + "\""
ini = datetime.now()
for image in imSet:
pathFile = fullPath(idOS,imPathRead,image)
# read
try:
img = PIL.Image.open(pathFile)
except Exception as e:
return "\"" + pathFile + "\": " + str(e)
img = img.convert("L")
aImg = asarray(img)
# process
x = aImg.shape[0]
y = aImg.shape[1]
f01 = aImg
for i in range(len(theta)):
f1 = rankFilterX(aImg,widthWindowRank,heightWindowRank,theta[i],pRank)
f01 = mmintersec(f01,f1)
# save
imageName = image[0:len(image)-4]
aFinal = array(f01,dtype=uint8)
imageOut = PIL.Image.fromarray(aFinal)
pathFileOut = fullPathSaveOut(idOS,imPathSave,imageName)
imageOut.save(pathFileOut,"TIFF")
print "File Created: ",pathFileOut
fim = datetime.now()
tempo = fim - ini
sys.stdout.write('\a')
sys.stdout.flush()
print tempo
if __name__ == "__main__":
sys.exit(main())