Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
193 lines (165 loc) · 5.25 KB
/
Copy pathmain.py
File metadata and controls
193 lines (165 loc) · 5.25 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
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
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Basilius Sauter
#
# Created: 07.05.2015
# Copyright: (c) Basilius Sauter 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
import os
import argparse
import numpy as np
from contour import Contour, AlternativeContour, NewContour, NoConvergenceError, OutOfBoundaryError
from filehandler import DatastorageFileHandler
from imagefilehandler import ImageFileHandler
from fft import FFT
from barplotanimation import BarplotAnimation
from fluctuationspectra import FluctuationSpectra
from startpointdetector import StartpointDetector
#
# CONFIGURATION
#
#FILE_PREFIX = "cell-isotohyper"
#FILE_SUFFIX = ".tif"
#FILE_PATH = "./example-video"
FILE_PREFIX = "transition"
#FILE_PREFIX = "iso_singlecell_F"
#FILE_PREFIX = "hyp3_singlecell_D"
FILE_SUFFIX = ".tif"
FILE_PATH = ".\\example-video\\05-08-dev1-hyp1"
FILE_SUFFIX_CONTOUR = ".contour"
FILE_SUFFIX_FFT = ".fft"
#XCUT = (91, 91+266)
#YCUT = (646, 646+252)
X_CUT = (530, 530+262)
Y_CUT = (533, 533+276)
#X_CUT = (00, 280)
#Y_CUT = (950, 1200)
STARTSEARCH_Y = 100 #180
# Settings for Startpoint Detection
X_TRANS_CUT = (0, 800)
Y_TRANS_CUT = (0, 200)
LIMIT = 100000
OFFSET = 0
#LIMIT = 1
#OFFSET = 4114 #4117
#LIMIT = 200
#OFFSET = 4000
Y_SCALE = 100
X_SCALE_START = 1
NUM_OF_BINS = 37
BAR_WIDTH = 1.0
BAR_COLOR = 'b'
##WEIGHT_MATRIX = np.array([
## [36, 30, 24, 18, 12, 6, 12, 18, 24, 30, 36],
## [30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30],
## [24, 20, 16, 12, 8, 4, 8, 12, 16, 20, 24],
## [18, 15, 12, 9, 6, 3, 6, 9, 12, 15, 18],
## [12, 10, 8, 6, 4, 2, 4, 6, 8, 10, 12],
## [ 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6],
## [12, 10, 8, 6, 4, 2, 4, 6, 8, 10, 12],
## [18, 15, 12, 9, 6, 3, 6, 9, 12, 15, 18],
## [24, 20, 16, 12, 8, 4, 8, 12, 16, 20, 24],
## [30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30],
## [36, 30, 24, 18, 12, 6, 12, 18, 24, 30, 36],
##])
WEIGHT_MATRIX = np.array([
[9, 6, 3, 6, 9],
[6, 4, 2, 4, 6],
[4, 2, 1, 2, 4],
[6, 4, 2, 4, 6],
[9, 6, 3, 6, 9],
])
##WEIGHT_MATRIX = np.array([
## [0, 0, 0],
## [0, 1, 0],
## [0, 0, 0],
##])
#WEIGHT_MATRIX = 1/WEIGHT_MATRIX
##WEIGHT_MATRIX = np.array([
## [16, 12, 8, 4, 8, 12, 16],
## [12, 9, 6, 3, 6, 9, 12],
## [ 8, 6, 4, 2, 4, 1, 1],
## [ 4, 3, 2, 1, 2, 3, 4],
## [ 8, 6, 4, 2, 4, 1, 1],
## [12, 9, 6, 3, 6, 9, 12],
## [16, 12, 8, 4, 8, 12, 16],
##])
#
# DO NOT MODIFY DOWN HERE
#
def getFilename(path, pre, suf):
return os.path.join(path, pre+suf)
contourFilename = getFilename(FILE_PATH, FILE_PREFIX, FILE_SUFFIX_CONTOUR)
def findTransition():
fh = ImageFileHandler(FILE_PATH, FILE_PREFIX, FILE_SUFFIX)
fh.set_limit(LIMIT, OFFSET)
fh.cut(X_TRANS_CUT, Y_TRANS_CUT)
trans = StartpointDetector()
for framenumber, frame in fh:
if framenumber%100 == 0:
print("Frame Number", framenumber)
trans.append(frame, sourcetype = trans.fromPIL)
trans.plot()
trans.show()
def createContours():
fh = ImageFileHandler(FILE_PATH, FILE_PREFIX, FILE_SUFFIX)
fh.set_limit(LIMIT, OFFSET)
if len(X_CUT) == 2 and len(Y_CUT) == 2:
fh.cut(X_CUT, Y_CUT)
contourStorage = DatastorageFileHandler.new(contourFilename)
for framenumber, frame in fh:
if framenumber%100 == 0:
print("Frame Number ", framenumber)
#c = Contour.fromPIL(frame)
#c = AlternativeContour.fromPIL(frame)
#c = Contour.fromPIL(frame)
c = NewContour.fromPIL(frame)
#c.setWeight(WEIGHT_MATRIX)
try:
#c.applyDoubleSobel()
c.findContour(yAxis = STARTSEARCH_Y)
con = c.getContour(True)
if len(con) > 0:
contourStorage.append(con)
except NoConvergenceError as e:
print("[E] Skipped frame (NC)", framenumber)
continue
except OutOfBoundaryError as e:
print("[E] Skipped frame (OoB)", framenumber)
continue
contourStorage.close()
def createFFT():
contourStorage = DatastorageFileHandler.load(contourFilename)
plot = BarplotAnimation(NUM_OF_BINS//2+1, BAR_WIDTH, BAR_COLOR)
plot.set_lim((X_SCALE_START, NUM_OF_BINS//2+1), (0, Y_SCALE))
def a(contourStorage):
for value in contourStorage:
fft = FFT(value)
fft.transform(NUM_OF_BINS)
yield fft.getFFT()
plot.animate(a(contourStorage))
plot.show()
contourStorage.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run some CellPathfinder methods')
parser.add_argument('--method', nargs=1, required=True, help='Which method you\'d like to call (1, 2 or 3)')
args = parser.parse_args()
if '1' in args.method:
print("Create Contour")
createContours()
elif '2' in args.method:
createFFT()
elif '3' in args.method:
#createFluctuationSpectra()
pass
elif '4' in args.method:
findTransition()
else:
raise ValueError("--method should only be 1, 2 or 3")
#createContours()
#createFFT()
#createFluctuationSpectra()
# createWhatever