-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
76 lines (54 loc) · 2.57 KB
/
data.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
import glob
import cv2
import os
path_relative = os.getcwd()
def processar(path_in, separator, path_out,res,ton):
if ton == 'rgb':
img = cv2.imread(path_in) # lê
img = cv2.resize(img, (res, res)) # redimensiona
nome_img = path_in.split(separator)[1]
cv2.imwrite(path_out + nome_img, img) # salva
if ton == 'cinza':
img = cv2.imread(path_in,0) # lê
img = cv2.resize(img, (res, res)) # redimensiona
nome_img = path_in.split(separator)[1]
cv2.imwrite(path_out + nome_img, img) # salva
def split_imagens(path, path_mask, separator, separator_mask):
print('processando mask')
lista_images = glob.glob(path)
# images
for i in lista_images:
print('IMAGES -> processando image > ', i)
processar(i, separator, path_relative + '/data/imagens/retina/400/cinza/', 400, 'cinza')
processar(i, separator, path_relative + '/data/imagens/retina/400/rgb/', 400, 'rgb')
processar(i, separator, path_relative + '/data/imagens/retina/800/cinza/', 800, 'cinza')
processar(i, separator, path_relative + '/data/imagens/retina/800/rgb/', 800, 'rgb')
# mask
lista_mask = glob.glob(path_mask)
for i in lista_mask:
print('MASK -> processando image > ', i)
processar(i, separator_mask, path_relative + '/data/imagens/mask/400/', 400, 'cinza')
processar(i, separator_mask, path_relative + '/data/imagens/mask/800/', 800, 'cinza')
def pre_process_image(path):
list_images = path
print("total = ", len(list_images))
for i in list_images:
name = i.split('/src/')[1]
if '-' in name:
"""save in /mask/"""
name_mask = name.split('-')[0]
name_mask = name_mask + str('_mask.png')
cv2.imwrite(path_relative + '/data/imagens/RIM-ONE/mask/' + name_mask, cv2.imread(i))
print('processada imagem ', name_mask)
else:
"""save in /image/"""
name_image = name.split('.')[0]
name_image = name_image + str('.png')
cv2.imwrite(path_relative + '/data/imagens/RIM-ONE/image/' + name_image, cv2.imread(i))
print('processada imagem ', name_image)
if __name__ == '__main__':
#pre_process_image(glob.glob(path_relative + '/data/imagens/RIM-ONE/src/*.bmp'))
split_imagens(path='/home/nig/PycharmProjects/Segmentation/data/imagens/RIM-ONE/image/*.png',
path_mask='/home/nig/PycharmProjects/Segmentation/data/imagens/RIM-ONE/mask/*.png',
separator='/image/',
separator_mask='/mask/')