/
rad3d.py
47 lines (33 loc) · 1.13 KB
/
rad3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from ij.gui import Plot
from neigh import neighborhood_mean
from stacks import CellStack
def radial_distribution_3D(cs, max_rad):
# type: (CellStack, int) -> list
"""
Compute the 3D radial distribution in the given radius
Reference https://github.com/mcib3d/mcib3d-core/blob/master/src/main/java/mcib3d/image3d/ImageHandler.java
:return: Values of (half) the gaussian in list of length max_rad+1
"""
tab = []
for r in range(max_rad + 1):
mean = neighborhood_mean(cs, r + 1, r)
tab.append(mean)
return tab
def plot_rad3d(tab):
r = len(tab) - 1
idx = list(range(-r, r + 1))
val = tab[::-1] + tab[1:]
return Plot("3D radial distribution", "rad", "mean", idx, val)
def radius_thresh(rad3d, thresh):
# type: (list, float) -> int
"""
Find the radius of the cell from the 3D radial distribution counting the values above the given threshold
:param rad3d: Radial distribution obtained with radial_distribution_3D
:param thresh: Threshold value
:return: Radius
"""
r = 0
for r, v in enumerate(rad3d):
if v < thresh:
break
return r