-
Notifications
You must be signed in to change notification settings - Fork 1
/
CCSegStatResultDisplay
executable file
·271 lines (208 loc) · 7.57 KB
/
CCSegStatResultDisplay
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env python3
import os
import sys
import getopt
import errno
import csv
import h5py
import numpy
import scipy.stats
import matplotlib.pyplot as plt
import cv2
class CCSegStatResultsDisplayer:
def crossSimple(self, a, b):
c = numpy.zeros((3, 1))
c[0] = b.flat[2] * a.flat[1] - b.flat[1] * a.flat[2]
c[1] = b.flat[0] * a.flat[2] - b.flat[2] * a.flat[0]
c[2] = b.flat[1] * a.flat[0] - b.flat[0] * a.flat[1]
return c
def tubeSurface(self, vertices, valuesAtVertices, tubeRadius = 50):
a = numpy.take(vertices, [1], axis = 1) - numpy.take(vertices, [0], axis = 1)
b = numpy.array([[0], [0], [1]])
c = self.crossSimple(a, b)
if numpy.count_nonzero(c) > 0:
b = numpy.array([[1], [0], [0]])
c = self.crossSimple(a, b)
b = self.crossSimple(c, a)
normb = numpy.sqrt(numpy.sum(b * b))
if normb > 0:
b = b / normb
unitNormals = numpy.zeros_like(vertices)
unitNormals[:, 0] = numpy.array(b.ravel())
for z in range(vertices.shape[1] - 1):
a = numpy.take(vertices, [z + 1], axis = 1) - numpy.take(vertices, [z], axis = 1)
c = self.crossSimple(a, b)
oldB = numpy.array(b)
b = self.crossSimple(c, a)
normb = numpy.sqrt(numpy.sum(b * b))
if normb > 0:
b = b / normb
#print b.T
unitNormals[:, z + 1] = numpy.array(b.ravel())
#
# % determine the binormals, which is B = T x N
# % T = tangent
# % N = normal
tangentVectors = vertices - numpy.roll(vertices, 1, axis = 1)
binormalVectors = numpy.zeros_like(vertices)
binormalVectors[0] = tangentVectors[1] * unitNormals[2] - tangentVectors[2] * unitNormals[1]
binormalVectors[1] = tangentVectors[2] * unitNormals[0] - tangentVectors[0] * unitNormals[2]
binormalVectors[2] = tangentVectors[0] * unitNormals[1] - tangentVectors[1] * unitNormals[0]
speed = numpy.sqrt(numpy.sum(tangentVectors * tangentVectors, axis = 0))
binormalVectors = binormalVectors / speed
print(binormalVectors)
quit()
#
# BiNormalVectors = bsxfun(@rdivide, cross(TangentVectors, unitnormals, 2), speed);
# % hold off;
# % plot3(XYZ(:, 1), XYZ(:, 2), XYZ(:, 3), '*-');
# % hold on;
# % h = quiver3(XYZ(:, 1), XYZ(:, 2), XYZ(:, 3), unitnormals(:, 1), unitnormals(:, 2), unitnormals(:, 3));
# % set(h, 'Color', 'r');
# % h = quiver3(XYZ(:, 1), XYZ(:, 2), XYZ(:, 3), BiNormalVectors(:, 1), BiNormalVectors(:, 2), BiNormalVectors(:, 3));
# % set(h, 'Color', 'b');
#
# N = 20;
# ANGLES = linspace(0, 2 * pi, N + 1);
# ANGLES = ANGLES(1:N)';
#
# VCell = cell(size(XYZ, 1), 1);
# FCell = cell(size(XYZ, 1), 1);
#
# COSANGLES = cos(ANGLES);
# SINANGLES = sin(ANGLES);
# for z = 1:size(XYZ, 1)
# VR = (bsxfun(@times, COSANGLES, unitnormals(z, :)) + bsxfun(@times, SINANGLES, BiNormalVectors(z, :))) * R / 2;
# VCell{z} = bsxfun(@plus, XYZ(z, :), VR);
#
# I = (1:N)';
# % for each vertex make faces
# MinusOneLevel = I - 1;
# MinusOneLevel(MinusOneLevel == 0) = N;
# %F =
# FCell{z} = ...
# [I + (z - 1) * N, ... same level, same column
# mod(I, N) + 1 + (z - 1) * N, ... one level up, same column
# mod(I + z * N - 1, size(XYZ, 1) * N) + 1; ... same level, next column
# I + (z - 1) * N, ... same level, same column
# mod(I + z * N - 1, size(XYZ, 1) * N) + 1, ... same level, next column
# mod(MinusOneLevel + z * N - 1, size(XYZ, 1) * N) + 1]; ... one level down, next column
#
# %FCell{z} = ...
# % [I, mod((I + N) - 1, N * size(XYZ, 1)) + 1, mod(mod(I, N) + z * N, N * size(XYZ, 1)) + 1];
# %keyboard;
# % first row, I, I - 1, I + N
# % second row, I, I + N, I + N - 1
# end
#
# %streamline(VCell);
# F = cat(1, FCell{:});
# V = cat(1, VCell{:});
#
# %II = [repmat(1, N, 1); repmat(2, N, 1)];
# %CData = repmat(II(:)', size(XYZ, 1), 1);
# %CData = repmat(II(:), 1, size(XYZ, 1));
# CData = repmat(Data(:)', N, 1);
# CData = CData(:);
#
# % patch('Faces', F, 'Vertices', V, 'FaceColor', 'r', 'EdgeColor', 'k');
# % axis equal;
# % keyboard;
#
#
# function c=crossSimple(a,b)
#
# c(1) = b(3)*a(2) - b(2)*a(3);
# c(2) = b(1)*a(3) - b(3)*a(1);
# c(3) = b(2)*a(1) - b(1)*a(2);
def plotData(self, data, plotType = 'pvalue', groupLabels = None, legendText = None):
numNodes = numpy.size(data)
interpRange = numpy.array([numpy.min(self.idealCCInterpPoints[self.maskClosed]), numpy.max(self.idealCCInterpPoints[self.maskClosed])])
self.idealCCInterpPoints[self.maskClosed] = 1.0 - (self.idealCCInterpPoints[self.maskClosed] - interpRange[0]) / (interpRange[1] - interpRange[0])
self.idealCCInterpPoints[self.maskClosed] = self.idealCCInterpPoints[self.maskClosed] * (numNodes - 1.0) + 1.0
self.tubeSurface(numpy.concatenate((self.boundaryContour, numpy.zeros((1, self.boundaryContour.shape[1]))), axis = 0), data)
def __init__(self):
#TODO: put in non-hardcoded location for this file, DONE
#idealCCFile = 'ideal_cc.hdf5'
scriptPath = os.path.realpath(__file__)
(head, tail) = os.path.split(scriptPath)
idealCCFile = os.path.join(head, 'data', 'ideal_cc.hdf5')
if not os.path.isfile(idealCCFile):
print("ideal CC file not found")
quit()
FID = h5py.File(idealCCFile, 'r')
self.idealCCInterpPoints = numpy.array(FID["InterpPoints"]).T
FID.close()
self.maskClosed = numpy.nonzero(self.idealCCInterpPoints)
#print interpRange
T = numpy.uint8(self.idealCCInterpPoints > 0)
T = numpy.pad(T, [1, 1], mode='constant', constant_values=0)
#print T
#print T.dtype
boundaryContour, hierarchy = CCSegUtils.findContours(T, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
del hierarchy
del T
# the minus one is due to the padding we added
self.boundaryContour = numpy.squeeze(boundaryContour[0].T) - 1
self.boundaryContour = self.boundaryContour[:, 0::5]
#print boundaryContour
#print boundaryContour.shape
#plt.imshow(T)
#plt.colorbar()
#plt.gcf().set_size_inches((20, 10), forward = True)
#plt.show()
#plt.show()
# set up
#self.plotType = plotType
#quit()
def usage():
print("Usage: " + sys.argv[0] + " [options] <stattest hdf5 file>")
print()
print("\tDESCRIPTION")
print()
print("\t\tDisplays statistical analysis results on callosal thickness profiles created by CCSegStatTest")
print()
print("\tARGUMENTS")
print()
print("\t\t<stattest hdf5 file>: the hdf5 file produced by CCSegStatTest, must contain the following variables")
print("\t\t\tGroupLabels")
print("\t\t\tGroupIDX")
print("\t\t\tobservedP")
print("\t\t\tobservedT")
print("\t\t\tpermP")
print("\t\t\tomnibusP")
print("\t\t\tFDRP")
def main():
opts, args = getopt.getopt(sys.argv[1:], "h", [])
numpy.set_printoptions(precision = 3, formatter = {'float':lambda x: "%.3f" % x})
inputHDF5File = None
if len(args) != 1:
print("The number of arguments must be 1")
usage()
exit()
inputHDF5File = args[0]
if not os.path.isfile(inputHDF5File):
print("The input file does not exist")
quit()
#for o, a in opts:
# if o == '--cull-percent':
# try:
# cullPercent = float(a)
# except Exception:
# print "Cull percentage was not formatted in a valid way, it must be a floating point number"
# quit()
statOutput = dict()
FID = h5py.File(inputHDF5File, 'r')
statOutput["permP"] = numpy.array(FID["permP"])
statOutput["FDRP"] = numpy.array(FID["FDRP"])
statOutput["observedP"] = numpy.array(FID["observedP"])
statOutput["observedT"] = numpy.array(FID["observedT"])
statOutput["omnibusP"] = numpy.array(FID["omnibusP"])
statOutput["groupLabels"] = numpy.array(FID['groupLabels']).tolist()
FID.close()
numNodes = numpy.size(statOutput["permP"])
resultsDisplayer = CCSegStatResultsDisplayer()
resultsDisplayer.plotData(data = statOutput["permP"])
print(sys.argv[0])
if __name__ == "__main__":
main()