Skip to content

Commit 66f7822

Browse files
committed
feat: add fly augmentation
1 parent f2e7c01 commit 66f7822

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

deepem/data/augment/flyem/aug_16nm.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from augmentor import *
2+
3+
4+
def get_augmentation(
5+
is_train,
6+
box=None,
7+
missing=7,
8+
blur=7,
9+
lost=True,
10+
random=False,
11+
recompute=False,
12+
border=[],
13+
section_gap=0,
14+
mask_section_gap=False,
15+
**kwargs
16+
):
17+
augs = list()
18+
19+
# Brightness & contrast purterbation
20+
augs.append(
21+
MixedGrayscale2D(
22+
contrast_factor=0.5,
23+
brightness_factor=0.5,
24+
prob=1, skip=0.3))
25+
26+
# Missing section & misalignment
27+
to_blend = list()
28+
# Misalingments
29+
trans = Compose([Misalign((0, 3), margin=1),
30+
Misalign((0, 8), margin=1),
31+
Misalign((0, 13), margin=1)])
32+
33+
# Out-of-alignments
34+
slip = Compose([SlipMisalign((0, 3), interp=True, margin=1),
35+
SlipMisalign((0, 8), interp=True, margin=1),
36+
SlipMisalign((0, 13), interp=True, margin=1)])
37+
to_blend.append(Blend([trans, slip], props=[0.7, 0.3]))
38+
if is_train:
39+
to_blend.append(Blend([
40+
MisalignPlusMissing((2, 8), value=0, random=random),
41+
MisalignPlusMissing((2, 8), value=0, random=False)
42+
]))
43+
else:
44+
to_blend.append(MisalignPlusMissing((2, 8), value=0, random=False))
45+
if missing > 0:
46+
if is_train:
47+
to_blend.append(Blend([
48+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False),
49+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=random),
50+
MissingSection(maxsec=missing, individual=False, value=0, random=random),
51+
]))
52+
else:
53+
to_blend.append(
54+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False)
55+
)
56+
if lost:
57+
if is_train:
58+
to_blend.append(Blend([
59+
LostSection(1),
60+
LostPlusMissing(value=0, random=random),
61+
LostPlusMissing(value=0, random=False)
62+
]))
63+
augs.append(Blend(to_blend))
64+
65+
# Box
66+
if is_train:
67+
if box == 'noise':
68+
augs.append(
69+
NoiseBox(sigma=(1, 3), dims=(3, 13), margin=(1, 3, 3),
70+
density=0.3, skip=0.1)
71+
)
72+
elif box == 'fill':
73+
augs.append(
74+
FillBox(dims=(3, 13), margin=(1, 3, 3),
75+
density=0.3, skip=0.1)
76+
)
77+
78+
# Out-of-focus
79+
if blur > 0:
80+
augs.append(MixedBlurrySection(maxsec=blur))
81+
82+
# Warping
83+
if is_train:
84+
augs.append(Warp(skip=0.3, do_twist=False, rot_max=45.0, scale_max=1.1))
85+
86+
# Flip & rotate
87+
augs.append(FlipRotate())
88+
89+
# Create border
90+
if border:
91+
augs.append(Border(targets=border))
92+
93+
# Recompute connected components
94+
if recompute:
95+
augs.append(Label(targets=recompute))
96+
97+
# Section gap
98+
if section_gap > 0:
99+
augs.append(SectionGap(num_secs=section_gap, masked=mask_section_gap))
100+
101+
return Compose(augs)

0 commit comments

Comments
 (0)