annotate toolbox/imtools.py @ 0:6bec4fef6b2e draft

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