-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_imgAug.py
98 lines (65 loc) · 2.46 KB
/
test_imgAug.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
88
89
90
91
92
93
94
95
96
97
98
'''
@lanhuage: python
@Descripttion: image augmentation with labels.
@version: beta
@Author: xiaoshuyui
@Date: 2020-07-17 15:49:30
LastEditors: xiaoshuyui
LastEditTime: 2022-07-02 19:59:08
'''
import sys
sys.path.append("..")
import os
from convertmask.utils.methods.get_multi_shapes import getMultiShapes
from convertmask.utils.auglib.img_aug import (aug_labelimg, aug_labelme, imgFlip,
imgNoise, imgRotation, imgTranslation,
imgZoom)
from skimage import io
BASE_DIR = os.path.abspath(os.path.dirname(os.getcwd())) + os.sep + 'static'
# print(BASE_DIR)
imgPath = BASE_DIR + os.sep + 'test702.jpg'
labelPath = BASE_DIR + os.sep + 'test702.json'
yamlPath = BASE_DIR + os.sep + 'test702.yaml'
imgPath2 = BASE_DIR + os.sep + 'label_255.png'
labelPath2 = BASE_DIR + os.sep + 'label_255.xml'
if __name__ == "__main__":
#### test1
imgFlip(imgPath, labelPath)
imgNoise(imgPath, labelPath)
imgRotation(imgPath, labelPath)
imgTranslation(imgPath, labelPath)
imgZoom(imgPath, labelPath, 1.2)
#### test2
n = imgNoise(imgPath, labelPath, flag=False)
tmp = n['noise']
img, processedImg = tmp.oriImg, tmp.processedImg
r = imgRotation(img, processedImg, flag=False, angle=15)
tmp = r['rotation']
img, processedImg = tmp.oriImg, tmp.processedImg
t = imgTranslation(img, processedImg, flag=False)
tmp = t['trans']
img, processedImg = tmp.oriImg, tmp.processedImg
f = imgFlip(img, processedImg, flag=False)
tmp = f['h_v']
img, processedImg = tmp.oriImg, tmp.processedImg
parent_path = os.path.dirname(imgPath)
if os.path.exists(parent_path + os.sep + 'jsons_'):
pass
else:
os.makedirs(parent_path + os.sep + 'jsons_')
fileName = 'test'
io.imsave(
parent_path + os.sep + 'jsons_' + os.sep + fileName + '_assumble.jpg',
img)
assumbleJson = getMultiShapes(parent_path + os.sep + 'jsons_' + os.sep +
fileName + '_assumble.jpg',
processedImg,
flag=True,
labelYamlPath='')
saveJsonPath = parent_path + os.sep + 'jsons_' + os.sep + fileName + '_assumble.json'
with open(saveJsonPath, 'w') as f:
f.write(assumbleJson)
#### test3
aug_labelme(imgPath, labelPath,yamlFilePath=yamlPath)
#### test4
# aug_labelimg(imgPath2, labelPath2)