Skip to content

Commit f120ceb

Browse files
committed
feat: data augmentation for dacey human retina
1 parent 324873b commit f120ceb

File tree

2 files changed

+197
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)