-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsvcreator.py
199 lines (157 loc) · 6.05 KB
/
csvcreator.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from os import listdir
import cv2
import pandas as pd
fileDir = "/Users/pc/Downloads/ChinaSet_AllFiles/CXR_png"
listOfFiles = listdir(fileDir)
print(listOfFiles)
class CSV():
def __init__(self, listOfFiles):
self.listOfFiles = listOfFiles
# def TBclassification(indexAnnot):
# fileName = listOfFiles[indexAnnot]
# fileType = ".png"
# if fileName.endswith(fileType):
# returnValue = int(fileName[12])
# return returnValue
# else:
# print(fileName)
# print('Invalid file')
#
# def createTBList(self):
# for classIndex in range(0, 10008):
# tbIndex = TBclassification(classIndex)
# tbList.append(tbIndex)
def FindFileBin(self):
fileType = ".png"
tbList = []
for num in range(1, len(listOfFiles) - 1):
currentFile = listOfFiles[num]
fileName = fileDir + '/' + currentFile
# for fileNameExact in listOfFiles:
if currentFile.endswith(fileType):
returnValue = int(currentFile[12])
tbList.append(returnValue)
if num == 662:
return tbList
if fileName == "NoneType":
break
def FindFile(self):
fileType = ".png"
fileList = []
for num in range(1, len(listOfFiles) - 1):
currentFile = listOfFiles[num]
fileName = fileDir + '/' + currentFile
# for fileNameExact in listOfFiles:
if currentFile.endswith(fileType):
returnValue = fileName
fileList.append(returnValue)
if num == 662:
return fileList
if fileName == "NoneType":
break
# return tbList
def Twosides(self,):
fileType = ".png"
for img in listOfFiles:
if img.endswith(fileType):
for num in range(1, len(listOfFiles) - 1):
currentFile = listOfFiles[num]
fileName = fileDir + '/' + currentFile
img = cv2.imread(fileName, 0)
img2 = img.copy()
print(img2)
# Makes a copy
updatedImgRow = []
updatedImg = []
for pixelrow in img2:
sumOfPixelsLeft = 0
sumOfPixelsRight = 0
count = 0
for pixel in pixelrow:
count += 1
if count <= 1500:
sumOfPixelsLeft += pixel
else:
sumOfPixelsRight += pixel
updatedImgRow.append([sumOfPixelsLeft,sumOfPixelsRight])
updatedSumLeft = 0
updatedSumRight = []
for index in range(len(updatedImgRow)):
updatedSumLeft = (updatedImgRow[index][0])
updatedSumRight = (updatedImgRow[index][1])
totalSumLeft = sum(updatedSumLeft)
totalSumRight = sum(updatedSumRight)
print(totalSumLeft)
print(totalSumRight)
# asa
for x in currentFile:
updatedImg.append(updatedImgRow)
print(updatedImg)
# return updatedImg
if img == "NoneType":
break
csvObject = CSV(listOfFiles)
binList = csvObject.FindFileBin()
dirList = csvObject.FindFile()
pixels = csvObject.Twosides()
print(pixels)
name of file,left,sumofRight
file1,790000,6900000
file2,777,888
# fileFullName, TBbinary = CreateCSV(num)
# print(fileFullName, TBbinary)
# f = pd.DataFrame(data={'FileName': [fileFullName], 'TBBinary': [TBbinary], 'TotalPixelsL': [sumOfPixelsLeft], 'TotalPixelsR': [sumOfPixelsRight]})
# f.append({'FileName': [fileFullName], 'TBBinary': [TBbinary], 'TotalPixelsL': sumOfPixelsLeft, 'TotalPixelsR': sumOfPixelsRight}, ignore_index=True)
# f.to_csv('imagedata.csv', index=False)
# print(sumOfPixelsLeft, sumOfPixelsRight)
# csv_input = pd.read_csv('imagedata.csv')
# for fileIndex in range(len(listOfFiles)):
# fileFullName, TBbinary = CreateCSV(fileIndex)
# print(fileFullName, TBbinary)
# f = pd.DataFrame(data = {'FileName':[fileFullName], 'TBBinary':[TBbinary], })
# # f.append({'FileName':[fileFullName], 'TBBinary':[TBbinary]}, ignore_index=True)
# # csv_input['Berries'] = csv_input['Name']
# f.to_csv('imagedata.csv', index=False)
# changes = fileList, TBList
# new_rows = []
# with open('imagedata.csv', 'r') as File:
# reader = csv.reader(File)
# for row in reader:
# print(row)
# new_row = row
# for key, value in changes.items(): # iterate over 'changes' dictionary
# new_row = [sub.replace(key, value) for sub in new_row] # make the substitutions
# print(new_row)
# new_rows.append(new_row)
# fileList = []
# TBList = []
# for fileIndex in range(1,len(listOfFiles)):
# print(fileIndex)
# fileFullName, TBbinary = CreateCSV(fileIndex)
# print(fileFullName, TBbinary)
# fileList.append(fileFullName)
# TBList.append(TBbinary)
# >>> print row0
# ['Name', 'Code', 'berry']
# >>> for item in r:
# ... item.append(item[0])
# ... print item
# ...
# ['blackberry', '1', 'blackberry']
# ['wineberry', '2', 'wineberry']
# ['rasberry', '1', 'rasberry']
# ['blueberry', '1', 'blueberry']
# ['mulberry', '2', 'mulberry']
# with open('imagedata.csv', 'a') as File:
# r = csv.reader(File)
# row0 = r.next()
# row0.append('berry')
# # writer = csv.writer(File)
# for fileIndex in range(1, len(listOfFiles)):
# fileFullName, TBbinary = CreateCSV(fileIndex)
# print(fileFullName, TBbinary)
# writer.writerows([[fileFullName], [TBbinary]])
# >>> f
# Animal Color
# 0 cow blue
# 1 horse red