Skip to content

Commit ae3de2f

Browse files
author
donglaiw
committed
remove negative part for saving
1 parent 9ad1983 commit ae3de2f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

connectomics/data/utils/data_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def seg2inst_edt(label, topt):
291291
_, mode, padding, quant, z_res, erosion = topt.split('-')
292292
resolution = (float(z_res), 1.0, 1.0)
293293
return edt_instance(label.copy(), mode, resolution=resolution,
294-
quantize=bool(int(quant)), padding=bool(int(padding)), erosion=erosion)
294+
quantize=bool(int(quant)), padding=bool(int(padding)), erosion=int(erosion))
295295

296296

297297
def seg_to_targets(

connectomics/data/utils/data_transform.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import scipy
66
import numpy as np
77
from scipy.ndimage import distance_transform_edt
8-
from skimage.morphology import remove_small_holes, skeletonize, binary_erosion, disk
8+
from skimage.morphology import remove_small_holes, skeletonize, binary_erosion, disk, ball
99
from skimage.measure import label as label_cc # avoid namespace conflict
1010
from skimage.filters import gaussian
1111

@@ -61,7 +61,7 @@ def edt_instance(label: np.ndarray,
6161
mode: str = '2d',
6262
quantize: bool = True,
6363
resolution: Tuple[float] = (1.0, 1.0, 1.0),
64-
padding: bool = False),
64+
padding: bool = False,
6565
erosion: int = 0):
6666
assert mode in ['2d', '3d']
6767
if mode == '3d':
@@ -151,11 +151,14 @@ def distance_transform(label: np.ndarray,
151151

152152
if not all_bg_sample:
153153
if erosion > 0:
154-
erosion_disk = disk(erosion)
154+
if label.ndim == 2:
155+
footprint = disk(erosion)
156+
elif label.ndim == 3:
157+
footprint = ball(erosion)
155158
for idx in indices:
156159
temp2 = remove_small_holes(label == idx, 16, connectivity=1)
157160
if erosion > 0:
158-
temp2 = binary_erosion(temp2, erosion_disk)
161+
temp2 = binary_erosion(temp2, footprint)
159162

160163
semantic += temp2.astype(np.uint8)
161164
boundary_edt = distance_transform_edt(temp2, resolution)

connectomics/engine/trainer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def test(self):
250250
if result[vol_id].ndim > weight[vol_id].ndim:
251251
weight[vol_id] = np.expand_dims(weight[vol_id], axis=0)
252252
result[vol_id] /= weight[vol_id] # in-place to save memory
253+
# remoe negative part for quantization
254+
result[vol_id][result[vol_id]<0] = 0
253255
result[vol_id] *= 255
254256
result[vol_id] = result[vol_id].astype(np.uint8)
255257

0 commit comments

Comments
 (0)