@@ -40,6 +40,16 @@ def find_objects(labels):
40
40
all_slices = scipy .ndimage .find_objects (labels .T )
41
41
return [ (slcs and slcs [::- 1 ]) for slcs in all_slices ]
42
42
43
+ def add_property (skel , prop ):
44
+ needs_prop = True
45
+ for skel_prop in skel .extra_attributes :
46
+ if skel_prop ["id" ] == prop ["id" ]:
47
+ needs_prop = False
48
+ break
49
+
50
+ if needs_prop :
51
+ skel .extra_attributes .append (prop )
52
+
43
53
def cross_sectional_area (
44
54
all_labels :np .ndarray ,
45
55
skeletons :Union [Dict [int ,Skeleton ],List [Skeleton ],Skeleton ],
@@ -49,6 +59,7 @@ def cross_sectional_area(
49
59
in_place :bool = False ,
50
60
fill_holes :bool = False ,
51
61
repair_contacts :bool = False ,
62
+ visualize_section_planes :bool = False ,
52
63
) -> Union [Dict [int ,Skeleton ],List [Skeleton ],Skeleton ]:
53
64
"""
54
65
Given a set of skeletons, find the cross sectional area
@@ -79,6 +90,9 @@ def cross_sectional_area(
79
90
that have a nonzero value for
80
91
skel.cross_sectional_area_contacts. This is intended
81
92
to be used as a second pass after widening the image.
93
+
94
+ visualize_section_planes: For debugging, paint section planes
95
+ and display them using microviewer.
82
96
"""
83
97
prop = {
84
98
"id" : "cross_sectional_area" ,
@@ -127,6 +141,10 @@ def cross_sectional_area(
127
141
128
142
binimg = np .asfortranarray (all_labels [slices ] == label )
129
143
144
+ cross_sections = None
145
+ if visualize_section_planes :
146
+ cross_sections = np .zeros (binimg .shape , dtype = np .uint32 , order = "F" )
147
+
130
148
if fill_holes :
131
149
binimg = fill_voids .fill (binimg , in_place = True )
132
150
@@ -177,16 +195,18 @@ def cross_sectional_area(
177
195
normal , anisotropy ,
178
196
return_contact = True ,
179
197
)
180
-
181
- needs_prop = True
182
- for skel_prop in skel .extra_attributes :
183
- if skel_prop ["id" ] == "cross_sectional_area" :
184
- needs_prop = False
185
- break
186
-
187
- if needs_prop :
188
- skel .extra_attributes .append (prop )
189
-
198
+ if visualize_section_planes :
199
+ img = xs3d .cross_section (
200
+ binimg , vert ,
201
+ normal , anisotropy ,
202
+ )
203
+ cross_sections [img > 0 ] = idx
204
+
205
+ if visualize_section_planes :
206
+ import microviewer
207
+ microviewer .view (cross_sections , seg = True )
208
+
209
+ add_property (skel , prop )
190
210
skel .cross_sectional_area = areas
191
211
skel .cross_sectional_area_contacts = contacts
192
212
0 commit comments