-
Notifications
You must be signed in to change notification settings - Fork 2
/
BM_kernel.py
executable file
·134 lines (108 loc) · 3.68 KB
/
BM_kernel.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#########################################################################################
# Copyright (c) 2017 Francisco Perdigon Romero
# Authors: Francisco Perdigon Romero
# email: 'fperdigon88@gmail.com'
# About the license: see the file LICENSE.TXT
#########################################################################################
__author__ = 'Francisco Perdigon Romero'
__email__ = 'fperdigon88@gmail.com'
import os
import csv
import time
# Bacillous Marks
Bacillus = []
BacillusCluster = []
Undefined = []
# Estatus Vars
ActImagesFolder = ''
ActImageName = ''
ActImageNumber = 0
ImagesList = []
AnnotationFolder = 'ImageAnnotation'
ExportFolder = 'ExportedImages'
CountFolder = 'CountFolder'
ActImageModifiedMarks = False
CSVMarkList = []
LogFolder = 'ImageLog'
UserNameTypeList = []
ActUserNameType = []
def GetBMPImagesInFolder(Path):
"""Esta funcao gera uma lista das images no folder"""
global ImagesList
global CSVMarkList
global AnnotationFolder
ImagesList = []
CSVMarkList = []
for file in os.listdir(Path):
if file[-3:] == 'bmp' or file[-3:] == 'BMP':
ImagesList.append(Path + '/' +file)
CSVMarkList.append(Path + '/' + AnnotationFolder + '/' + file[:-3] + 'csv')
ImagesList.sort()
CSVMarkList.sort()
print('ImagesList')
print(ImagesList)
print('CSVList')
print(CSVMarkList)
return ImagesList
def CSVMarkRead(CSVFile):
"""Esta funcao lee as marcas guardadas no arquivo associado a imagem"""
global Bacillus
global BacillusCluster
global Undefined
Bacillus = []
BacillusCluster = []
Undefined = []
if os.path.exists(ActImagesFolder + '/' + AnnotationFolder) == False:
os.mkdir(ActImagesFolder + '/' + AnnotationFolder)
if os.path.isfile(CSVFile) == True:
with open(CSVFile, 'rb') as f:
reader = csv.reader(f)
for row in reader:
if row[0] == 'b':
Bacillus.append([row[0],int(row[1]),int(row[2])])
if row[0] == 'bc':
BacillusCluster.append([row[0],int(row[1]),int(row[2])])
if row[0] == 'u':
Undefined.append([row[0],int(row[1]),int(row[2])])
print('Variaveis recuperadas de CSV')
print(Bacillus)
print(BacillusCluster)
print(Undefined)
def CSVMarkWrite(CSVFile):
"""Esta funcao guarda as marcas guardadas no arquivo associado a imagem"""
global Bacillus
global BacillusCluster
global Undefined
with open(CSVFile, 'wb') as f:
writer = csv.writer(f)
writer.writerows(Bacillus)
writer.writerows(BacillusCluster)
writer.writerows(Undefined)
Bacillus = []
BacillusCluster = []
Undefined = []
print('Variaveis guardadas em CSV')
def CSVLogRead(CSVFile):
"""Esta funcao lee o Log da imagem"""
global UserNameTypeList
UserNameTypeList = []
if os.path.exists(ActImagesFolder + '/' + LogFolder) == False:
os.mkdir(ActImagesFolder + '/' + LogFolder)
if os.path.isfile(CSVFile) == True:
with open(CSVFile, 'rb') as f:
reader = csv.reader(f)
for row in reader:
UserNameTypeList.append([row[0], row[1], row[2]])
print('Log recuperado')
print(UserNameTypeList)
def CSVLogWrite(CSVFile):
"""Esta funcao guarda os usuarios que marcaram a imagem"""
global UserNameTypeList
global ActUserNameType
UserNameTypeList.append([ActUserNameType[0][0], ActUserNameType[0][1], time.strftime("%c")])
print(UserNameTypeList)
with open(CSVFile, 'wb') as f:
writer = csv.writer(f)
writer.writerows(UserNameTypeList)
UserNameTypeList = []
print('Log guardado')