annotate toolbox/imtools.py @ 1:57f1260ca94e draft

"planemo upload commit fec9dc76b3dd17b14b02c2f04be9d30f71eba1ae"
author watsocam
date Fri, 11 Mar 2022 23:40:51 +0000
parents 99308601eaa6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
1 import matplotlib.pyplot as plt
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
2 import tifffile
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
3 import os
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
4 import numpy as np
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
5 from skimage import io as skio
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
6 from scipy.ndimage import *
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
7 from skimage.morphology import *
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
8 from skimage.transform import resize
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
9
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
10 def tifread(path):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
11 return tifffile.imread(path)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
12
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
13 def tifwrite(I,path):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
14 tifffile.imsave(path, I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
15
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
16 def imshow(I,**kwargs):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
17 if not kwargs:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
18 plt.imshow(I,cmap='gray')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
19 else:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
20 plt.imshow(I,**kwargs)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
21
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
22 plt.axis('off')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
23 plt.show()
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
24
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
25 def imshowlist(L,**kwargs):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
26 n = len(L)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
27 for i in range(n):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
28 plt.subplot(1, n, i+1)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
29 if not kwargs:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
30 plt.imshow(L[i],cmap='gray')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
31 else:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
32 plt.imshow(L[i],**kwargs)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
33 plt.axis('off')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
34 plt.show()
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
35
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
36 def imread(path):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
37 return skio.imread(path)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
38
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
39 def imwrite(I,path):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
40 skio.imsave(path,I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
41
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
42 def im2double(I):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
43 if I.dtype == 'uint16':
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
44 return I.astype('float64')/65535
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
45 elif I.dtype == 'uint8':
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
46 return I.astype('float64')/255
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
47 elif I.dtype == 'float32':
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
48 return I.astype('float64')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
49 elif I.dtype == 'float64':
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
50 return I
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
51 else:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
52 print('returned original image type: ', I.dtype)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
53 return I
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
54
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
55 def size(I):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
56 return list(I.shape)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
57
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
58 def imresizeDouble(I,sizeOut): # input and output are double
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
59 return resize(I,(sizeOut[0],sizeOut[1]),mode='reflect')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
60
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
61 def imresize3Double(I,sizeOut): # input and output are double
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
62 return resize(I,(sizeOut[0],sizeOut[1],sizeOut[2]),mode='reflect')
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
63
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
64 def imresizeUInt8(I,sizeOut): # input and output are UInt8
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
65 return np.uint8(resize(I.astype(float),(sizeOut[0],sizeOut[1]),mode='reflect',order=0))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
66
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
67 def imresize3UInt8(I,sizeOut): # input and output are UInt8
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
68 return np.uint8(resize(I.astype(float),(sizeOut[0],sizeOut[1],sizeOut[2]),mode='reflect',order=0))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
69
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
70 def normalize(I):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
71 m = np.min(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
72 M = np.max(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
73 if M > m:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
74 return (I-m)/(M-m)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
75 else:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
76 return I
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
77
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
78 def snormalize(I):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
79 m = np.mean(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
80 s = np.std(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
81 if s > 0:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
82 return (I-m)/s
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
83 else:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
84 return I
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
85
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
86 def cat(a,I,J):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
87 return np.concatenate((I,J),axis=a)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
88
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
89 def imerode(I,r):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
90 return binary_erosion(I, disk(r))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
91
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
92 def imdilate(I,r):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
93 return binary_dilation(I, disk(r))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
94
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
95 def imerode3(I,r):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
96 return morphology.binary_erosion(I, ball(r))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
97
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
98 def imdilate3(I,r):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
99 return morphology.binary_dilation(I, ball(r))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
100
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
101 def sphericalStructuralElement(imShape,fRadius):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
102 if len(imShape) == 2:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
103 return disk(fRadius,dtype=float)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
104 if len(imShape) == 3:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
105 return ball(fRadius,dtype=float)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
106
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
107 def medfilt(I,filterRadius):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
108 return median_filter(I,footprint=sphericalStructuralElement(I.shape,filterRadius))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
109
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
110 def maxfilt(I,filterRadius):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
111 return maximum_filter(I,footprint=sphericalStructuralElement(I.shape,filterRadius))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
112
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
113 def minfilt(I,filterRadius):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
114 return minimum_filter(I,footprint=sphericalStructuralElement(I.shape,filterRadius))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
115
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
116 def ptlfilt(I,percentile,filterRadius):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
117 return percentile_filter(I,percentile,footprint=sphericalStructuralElement(I.shape,filterRadius))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
118
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
119 def imgaussfilt(I,sigma,**kwargs):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
120 return gaussian_filter(I,sigma,**kwargs)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
121
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
122 def imlogfilt(I,sigma,**kwargs):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
123 return -gaussian_laplace(I,sigma,**kwargs)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
124
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
125 def imgradmag(I,sigma):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
126 if len(I.shape) == 2:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
127 dx = imgaussfilt(I,sigma,order=[0,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
128 dy = imgaussfilt(I,sigma,order=[1,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
129 return np.sqrt(dx**2+dy**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
130 if len(I.shape) == 3:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
131 dx = imgaussfilt(I,sigma,order=[0,0,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
132 dy = imgaussfilt(I,sigma,order=[0,1,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
133 dz = imgaussfilt(I,sigma,order=[1,0,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
134 return np.sqrt(dx**2+dy**2+dz**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
135
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
136 def localstats(I,radius,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
137 ptls = [10,30,50,70,90]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
138 featNames = []
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
139 for i in range(len(ptls)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
140 featNames.append('locPtl%d' % ptls[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
141 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
142 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
143 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
144 nFeats = len(ptls)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
145 F = np.zeros((sI[0],sI[1],nFeats))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
146 for i in range(nFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
147 F[:,:,i] = ptlfilt(I,ptls[i],radius)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
148 return F
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
149
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
150 def localstats3(I,radius,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
151 ptls = [10,30,50,70,90]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
152 featNames = []
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
153 for i in range(len(ptls)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
154 featNames.append('locPtl%d' % ptls[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
155 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
156 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
157 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
158 nFeats = len(ptls)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
159 F = np.zeros((sI[0],sI[1],sI[2],nFeats))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
160 for i in range(nFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
161 F[:,:,:,i] = ptlfilt(I,ptls[i],radius)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
162 return F
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
163
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
164 def imderivatives(I,sigmas,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
165 if type(sigmas) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
166 sigmas = [sigmas]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
167 derivPerSigmaFeatNames = ['d0','dx','dy','dxx','dxy','dyy','normGrad','normHessDiag']
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
168 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
169 featNames = [];
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
170 for i in range(len(sigmas)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
171 for j in range(len(derivPerSigmaFeatNames)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
172 featNames.append('derivSigma%d%s' % (sigmas[i],derivPerSigmaFeatNames[j]))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
173 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
174 nDerivativesPerSigma = len(derivPerSigmaFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
175 nDerivatives = len(sigmas)*nDerivativesPerSigma
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
176 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
177 D = np.zeros((sI[0],sI[1],nDerivatives))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
178 for i in range(len(sigmas)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
179 sigma = sigmas[i]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
180 dx = imgaussfilt(I,sigma,order=[0,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
181 dy = imgaussfilt(I,sigma,order=[1,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
182 dxx = imgaussfilt(I,sigma,order=[0,2])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
183 dyy = imgaussfilt(I,sigma,order=[2,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
184 D[:,:,nDerivativesPerSigma*i ] = imgaussfilt(I,sigma)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
185 D[:,:,nDerivativesPerSigma*i+1] = dx
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
186 D[:,:,nDerivativesPerSigma*i+2] = dy
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
187 D[:,:,nDerivativesPerSigma*i+3] = dxx
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
188 D[:,:,nDerivativesPerSigma*i+4] = imgaussfilt(I,sigma,order=[1,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
189 D[:,:,nDerivativesPerSigma*i+5] = dyy
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
190 D[:,:,nDerivativesPerSigma*i+6] = np.sqrt(dx**2+dy**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
191 D[:,:,nDerivativesPerSigma*i+7] = np.sqrt(dxx**2+dyy**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
192 return D
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
193 # derivatives are indexed by the last dimension, which is good for ML features but not for visualization,
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
194 # in which case the expected dimensions are [plane,channel,y(row),x(col)]; to obtain that ordering, do
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
195 # D = np.moveaxis(D,[0,3,1,2],[0,1,2,3])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
196
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
197 def imderivatives3(I,sigmas,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
198 if type(sigmas) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
199 sigmas = [sigmas]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
200
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
201 derivPerSigmaFeatNames = ['d0','dx','dy','dz','dxx','dxy','dxz','dyy','dyz','dzz','normGrad','normHessDiag']
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
202
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
203 # derivPerSigmaFeatNames = ['d0','normGrad','normHessDiag']
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
204
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
205 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
206 featNames = [];
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
207 for i in range(len(sigmas)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
208 for j in range(len(derivPerSigmaFeatNames)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
209 featNames.append('derivSigma%d%s' % (sigmas[i],derivPerSigmaFeatNames[j]))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
210 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
211 nDerivativesPerSigma = len(derivPerSigmaFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
212 nDerivatives = len(sigmas)*nDerivativesPerSigma
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
213 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
214 D = np.zeros((sI[0],sI[1],sI[2],nDerivatives)) # plane, channel, y, x
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
215 for i in range(len(sigmas)):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
216 sigma = sigmas[i]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
217 dx = imgaussfilt(I,sigma,order=[0,0,1]) # z, y, x
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
218 dy = imgaussfilt(I,sigma,order=[0,1,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
219 dz = imgaussfilt(I,sigma,order=[1,0,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
220 dxx = imgaussfilt(I,sigma,order=[0,0,2])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
221 dyy = imgaussfilt(I,sigma,order=[0,2,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
222 dzz = imgaussfilt(I,sigma,order=[2,0,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
223
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
224 D[:,:,:,nDerivativesPerSigma*i ] = imgaussfilt(I,sigma)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
225 D[:,:,:,nDerivativesPerSigma*i+1 ] = dx
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
226 D[:,:,:,nDerivativesPerSigma*i+2 ] = dy
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
227 D[:,:,:,nDerivativesPerSigma*i+3 ] = dz
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
228 D[:,:,:,nDerivativesPerSigma*i+4 ] = dxx
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
229 D[:,:,:,nDerivativesPerSigma*i+5 ] = imgaussfilt(I,sigma,order=[0,1,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
230 D[:,:,:,nDerivativesPerSigma*i+6 ] = imgaussfilt(I,sigma,order=[1,0,1])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
231 D[:,:,:,nDerivativesPerSigma*i+7 ] = dyy
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
232 D[:,:,:,nDerivativesPerSigma*i+8 ] = imgaussfilt(I,sigma,order=[1,1,0])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
233 D[:,:,:,nDerivativesPerSigma*i+9 ] = dzz
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
234 D[:,:,:,nDerivativesPerSigma*i+10] = np.sqrt(dx**2+dy**2+dz**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
235 D[:,:,:,nDerivativesPerSigma*i+11] = np.sqrt(dxx**2+dyy**2+dzz**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
236
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
237 # D[:,:,:,nDerivativesPerSigma*i ] = imgaussfilt(I,sigma)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
238 # D[:,:,:,nDerivativesPerSigma*i+1 ] = np.sqrt(dx**2+dy**2+dz**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
239 # D[:,:,:,nDerivativesPerSigma*i+2 ] = np.sqrt(dxx**2+dyy**2+dzz**2)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
240 return D
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
241 # derivatives are indexed by the last dimension, which is good for ML features but not for visualization,
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
242 # in which case the expected dimensions are [plane,y(row),x(col)]; to obtain that ordering, do
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
243 # D = np.moveaxis(D,[2,0,1],[0,1,2])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
244
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
245 def imfeatures(I=[],sigmaDeriv=1,sigmaLoG=1,locStatsRad=0,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
246 if type(sigmaDeriv) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
247 sigmaDeriv = [sigmaDeriv]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
248 if type(sigmaLoG) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
249 sigmaLoG = [sigmaLoG]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
250 derivFeatNames = imderivatives([],sigmaDeriv,justfeatnames=True)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
251 nLoGFeats = len(sigmaLoG)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
252 locStatsFeatNames = []
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
253 if locStatsRad > 1:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
254 locStatsFeatNames = localstats([],locStatsRad,justfeatnames=True)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
255 nLocStatsFeats = len(locStatsFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
256 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
257 featNames = derivFeatNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
258 for i in range(nLoGFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
259 featNames.append('logSigma%d' % sigmaLoG[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
260 for i in range(nLocStatsFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
261 featNames.append(locStatsFeatNames[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
262 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
263 nDerivFeats = len(derivFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
264 nFeatures = nDerivFeats+nLoGFeats+nLocStatsFeats
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
265 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
266 F = np.zeros((sI[0],sI[1],nFeatures))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
267 F[:,:,:nDerivFeats] = imderivatives(I,sigmaDeriv)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
268 for i in range(nLoGFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
269 F[:,:,nDerivFeats+i] = imlogfilt(I,sigmaLoG[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
270 if locStatsRad > 1:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
271 F[:,:,nDerivFeats+nLoGFeats:] = localstats(I,locStatsRad)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
272 return F
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
273
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
274 def imfeatures3(I=[],sigmaDeriv=2,sigmaLoG=2,locStatsRad=0,justfeatnames=False):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
275 if type(sigmaDeriv) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
276 sigmaDeriv = [sigmaDeriv]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
277 if type(sigmaLoG) is not list:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
278 sigmaLoG = [sigmaLoG]
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
279 derivFeatNames = imderivatives3([],sigmaDeriv,justfeatnames=True)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
280 nLoGFeats = len(sigmaLoG)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
281 locStatsFeatNames = []
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
282 if locStatsRad > 1:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
283 locStatsFeatNames = localstats3([],locStatsRad,justfeatnames=True)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
284 nLocStatsFeats = len(locStatsFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
285 if justfeatnames == True:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
286 featNames = derivFeatNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
287 for i in range(nLoGFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
288 featNames.append('logSigma%d' % sigmaLoG[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
289 for i in range(nLocStatsFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
290 featNames.append(locStatsFeatNames[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
291 return featNames
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
292 nDerivFeats = len(derivFeatNames)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
293 nFeatures = nDerivFeats+nLoGFeats+nLocStatsFeats
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
294 sI = size(I)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
295 F = np.zeros((sI[0],sI[1],sI[2],nFeatures))
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
296 F[:,:,:,:nDerivFeats] = imderivatives3(I,sigmaDeriv)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
297 for i in range(nLoGFeats):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
298 F[:,:,:,nDerivFeats+i] = imlogfilt(I,sigmaLoG[i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
299 if locStatsRad > 1:
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
300 F[:,:,:,nDerivFeats+nLoGFeats:] = localstats3(I,locStatsRad)
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
301 return F
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
302
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
303 def stack2list(S):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
304 L = []
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
305 for i in range(size(S)[2]):
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
306 L.append(S[:,:,i])
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
307 return L
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
308
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
309 def thrsegment(I,wsBlr,wsThr): # basic threshold segmentation
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
310 G = imgaussfilt(I,sigma=(1-wsBlr)+wsBlr*5) # min 1, max 5
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
311 M = G > wsThr
99308601eaa6 "planemo upload for repository https://github.com/ohsu-comp-bio/UNetCoreograph commit fb90660a1805b3f68fcff80d525b5459c3f7dfd6-dirty"
perssond
parents:
diff changeset
312 return M