-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessDirectory.py
54 lines (48 loc) · 2.12 KB
/
ProcessDirectory.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
'''
Created on Nov, 29 2016
@author: Caleb Hulbert
'''
from Tkinter import Tk
import tkFileDialog
import os
import Repline
def start(startindirectory='', write=True, clustertype='kmeans', stats='False'):
Tk().withdraw()
if startindirectory == '':
startindirectory = str(tkFileDialog.askdirectory())
print str(startindirectory)
repnames = []
for cobfile in os.listdir(startindirectory):
if ".tif.csv" in cobfile and "1_" in cobfile:
#Remove .csv
repname = os.path.splitext(cobfile)[0]
#Remove .tif
repname = os.path.splitext(repname)[0]
# remove leading number and underscore
repname = repname[repname.find('_') + 1:]
repnames.append(repname)
allcolorinfo = [["Repline", "Pixels in Cluster", "L", "a", "b"]]
print "Constructing Replines"
for namenum in xrange(len(repnames)):
repline = Repline.Repline(
startInDirectory=startindirectory, row=repnames[namenum], clustertype=clustertype, stats=stats)
for cluster in repline.clusters:
colorinfo = [repnames[namenum], cluster[0], cluster[1][0], cluster[1][1], cluster[1][2]]
allcolorinfo.append(colorinfo)
# print colorinfo
if namenum < len(repnames) - 1:
print "(", namenum + 1, "/", len(repnames), ")", "Finished: ", repline.name, "Constructing ", repnames[namenum + 1], "..."
elif namenum == len(repnames):
print "(", namenum + 1, "/", len(repnames), ")", "Finished: ", repline.name
print "Done!"
newFile = str(startindirectory) + "/TotalStats.csv"
with open(newFile, 'w') as results:
for line in allcolorinfo:
print line
results.write("%s,%s,%s,%s,%s" % (line[0], line[1], line[2],line[3],line[4]))
results.write("\n")
return allcolorinfo
def test():
start('C:/Users/cmhul/Google Drive/College_/Corn_Color_Phenotyping/Landrace_Colorimeter_and_Pictures/Kernel CSVs')
if __name__ == '__main__':
start('C:/Users/cmhul/Google Drive/College_/Corn_Color_Phenotyping/Landrace_Colorimeter_and_Pictures/Kernel CSVs')