Skip to content

Commit b271bab

Browse files
author
donglaiw
committed
update polarity2instance with cc3d and memory handling
1 parent 97a8792 commit b271bab

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

connectomics/utils/process.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from skimage.segmentation import watershed
1010
from skimage.morphology import remove_small_objects
1111
from skimage.feature import peak_local_max
12+
import cc3d
1213

1314
from connectomics.data.utils import getSegType, bbox_ND, crop_ND, replace_ND
1415

@@ -290,7 +291,9 @@ def polarity2instance(
290291
# The pre- and post-synaptic masks may not touch each other. Dilating the
291292
# union masks to define each synapse instance.
292293
foreground = binary_dilation(temp[2], np.ones((1,dilate_sz,dilate_sz), bool))
293-
foreground = label(foreground)
294+
del temp
295+
296+
foreground = cast2dtype(cc3d.connected_components(foreground, connectivity=6))
294297

295298
# Since non-zero pixels in seg_pos and seg_neg are subsets of temp[2],
296299
# they are naturally subsets of non-zero pixels in foreground.
@@ -306,6 +309,7 @@ def polarity2instance(
306309
num_syn = min(num_pre, num_post) # a conservative estimate
307310
print(f"Stats: found {num_pre} pre- and {num_post} post-synaptic segments.")
308311
print(f"There are {num_syn} synapses under a conservative estimate.")
312+
del seg_pre, seg_post
309313

310314
# resize the segmentation based on specified scale factors
311315
if not all(x==1.0 for x in scale_factors):

0 commit comments

Comments
 (0)