-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmomutils.py
94 lines (71 loc) · 2.02 KB
/
momutils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
from scipy.ndimage import label
# ------------------------------------------------------------
# SHAPE OF A BINARY OBJECT
# ------------------------------------------------------------
def mask_shape(
x,
y = None,
z = None
):
"""
"""
# Initialize the output
obj_shape = {}
# -=-=-=-=-=
# 1-D extent
# -=-=-=-=-=
# ... X
obj_shape["minx"] = np.min(x)
obj_shape["maxx"] = np.max(x)
obj_shape["deltax"] = obj_shape["maxx"]-obj_shape["minx"]+1
# ... Y
if y != None:
obj_shape["miny"] = np.min(y)
obj_shape["maxy"] = np.max(y)
obj_shape["deltay"] = obj_shape["maxy"]-obj_shape["miny"]+1
# ... Z
if z != None:
obj_shape["minz"] = np.min(z)
obj_shape["maxz"] = np.max(z)
obj_shape["deltaz"] = obj_shape["maxz"]-obj_shape["minz"]+1
# -=-=-=-=-=
# 2-D extent
# -=-=-=-=-=
# Create a number that maps to a unique 2-d position out of pairs
# of coordinates and then note the area by counting the unique
# set of such numbers.
# ... XY
if y != None:
obj_shape["areaxy"] = len(np.unique(y*(obj_shape["maxx"]+1) + x))
if z != None:
# ... XZ
obj_shape["areaxz"] = len(np.unique(z*(obj_shape["maxx"]+1) + x))
# ... YZ
obj_shape["areayz"] = len(np.unique(z*(obj_shape["maxy"]+1) + y))
# -=-=-=-=-=
# 3-D extent
# -=-=-=-=-=
# Equate the volume to the set of pixels
obj_shape["volume"] = len(x)
# -=-=-=-=-=-=-=
# Richer measures
# -=-=-=-=-=-=-=
# ... perimeter by plane
# ... longest chord by plane
# ... best fit ellipse
# ... roundness
# ... would cost more, too
# Return the dictionary
return obj_shape
# ------------------------------------------------------------
# STRUCTURE OF AN OBJECT WITH DATA VALUES
# ------------------------------------------------------------
def stat_0d():
pass
def stat_1d():
pass
def stat_2d():
pass
def stat_3d():
pass