forked from aleju/imgaug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_superpixels.py
38 lines (27 loc) · 946 Bytes
/
check_superpixels.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
from __future__ import print_function, division
import time
from itertools import cycle
import cv2
import numpy as np
from skimage import data
import imgaug as ia
from imgaug import augmenters as iaa
POINT_SIZE = 5
SEGMENTS_PER_STEP = 1
TIME_PER_STEP = 10
def main():
image = data.astronaut()[..., ::-1] # rgb2bgr
print(image.shape)
cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
cv2.imshow("aug", image)
cv2.waitKey(TIME_PER_STEP)
for n_segments in cycle(reversed(np.arange(1, 200, SEGMENTS_PER_STEP))):
aug = iaa.Superpixels(p_replace=0.75, n_segments=n_segments)
time_start = time.time()
img_aug = aug.augment_image(image)
print("augmented %d in %.4fs" % (n_segments, time.time() - time_start))
img_aug = ia.draw_text(img_aug, x=5, y=5, text="%d" % (n_segments,))
cv2.imshow("aug", img_aug)
cv2.waitKey(TIME_PER_STEP)
if __name__ == "__main__":
main()