forked from aleju/imgaug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_fixed_size.py
87 lines (74 loc) · 3.37 KB
/
check_fixed_size.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import print_function, division
import numpy as np
import imgaug as ia
from imgaug import augmenters as iaa
def main():
image = ia.data.quokka(size=0.5)
kps = [ia.KeypointsOnImage(
[ia.Keypoint(x=245, y=203), ia.Keypoint(x=365, y=195), ia.Keypoint(x=313, y=269)],
shape=(image.shape[0]*2, image.shape[1]*2)
)]
kps[0] = kps[0].on(image.shape)
print("image shape:", image.shape)
augs_many = [
iaa.PadToFixedSize(200, 200, name="pad-width200-height200"),
iaa.PadToFixedSize(200, 322, name="pad-width200-height322"),
iaa.PadToFixedSize(200, 400, name="pad-width200-height400"),
iaa.PadToFixedSize(480, 200, name="pad-width480-height200"),
iaa.PadToFixedSize(480, 322, name="pad-width480-height322"), # input size == output size
iaa.PadToFixedSize(480, 400, name="pad-width480-height400"),
iaa.PadToFixedSize(600, 200, name="pad-width600-height200"),
iaa.PadToFixedSize(600, 322, name="pad-width600-height322"),
iaa.PadToFixedSize(600, 400, name="pad-width600-height400"),
iaa.CropToFixedSize(200, 200, name="crop-width200-height200"),
iaa.CropToFixedSize(200, 322, name="crop-width200-height322"),
iaa.CropToFixedSize(200, 400, name="crop-width200-height400"),
iaa.CropToFixedSize(480, 200, name="crop-width480-height200"),
iaa.CropToFixedSize(480, 322, name="crop-width480-height322"), # input size == output size
iaa.CropToFixedSize(480, 400, name="crop-width480-height400"),
iaa.CropToFixedSize(600, 200, name="crop-width600-height200"),
iaa.CropToFixedSize(600, 322, name="crop-width600-height322"),
iaa.CropToFixedSize(600, 400, name="crop-width600-height400"),
iaa.Sequential([
iaa.PadToFixedSize(200, 200),
iaa.CropToFixedSize(200, 200)
], name="pad-crop-width200-height200"),
iaa.Sequential([
iaa.PadToFixedSize(400, 400),
iaa.CropToFixedSize(400, 400)
], name="pad-crop-width400-height400"),
iaa.Sequential([
iaa.PadToFixedSize(600, 600),
iaa.CropToFixedSize(600, 600)
], name="pad-crop-width600-height600"),
iaa.Sequential([
iaa.CropToFixedSize(200, 200),
iaa.PadToFixedSize(200, 200)
], name="crop-pad-width200-height200"),
iaa.Sequential([
iaa.CropToFixedSize(400, 400),
iaa.PadToFixedSize(400, 400)
], name="crop-pad-width400-height400"),
iaa.Sequential([
iaa.CropToFixedSize(600, 600),
iaa.PadToFixedSize(600, 600)
], name="crop-pad-width600-height600"),
]
print("original", image.shape)
ia.imshow(kps[0].draw_on_image(image))
print("-----------------")
print("Random aug per image")
print("-----------------")
for aug in augs_many:
images_aug = []
for _ in range(36):
aug_det = aug.to_deterministic()
img_aug = aug_det.augment_image(image)
kps_aug = aug_det.augment_keypoints(kps)[0]
img_aug_kps = kps_aug.draw_on_image(img_aug)
img_aug_kps = np.pad(img_aug_kps, ((1, 1), (1, 1), (0, 0)), mode="constant", constant_values=255)
images_aug.append(img_aug_kps)
print(aug.name)
ia.imshow(ia.draw_grid(images_aug))
if __name__ == "__main__":
main()