-
Notifications
You must be signed in to change notification settings - Fork 136
/
preprocessing.py
63 lines (50 loc) · 1.55 KB
/
preprocessing.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
import numpy as np
import cv2
import os
import csv
from image_processing import func
if not os.path.exists("data2"):
os.makedirs("data2")
if not os.path.exists("data2/train"):
os.makedirs("dataluv/train")
if not os.path.exists("data2/test"):
os.makedirs("data2/test")
path="train"
path1 = "data2"
a=['label']
for i in range(64*64):
a.append("pixel"+str(i))
#outputLine = a.tolist()
label=0
var = 0
c1 = 0
c2 = 0
for (dirpath,dirnames,filenames) in os.walk(path):
for dirname in dirnames:
print(dirname)
for(direcpath,direcnames,files) in os.walk(path+"/"+dirname):
if not os.path.exists(path1+"/train/"+dirname):
os.makedirs(path1+"/train/"+dirname)
if not os.path.exists(path1+"/test/"+dirname):
os.makedirs(path1+"/test/"+dirname)
# num=0.75*len(files)
num = 100000000000000000
i=0
for file in files:
var+=1
actual_path=path+"/"+dirname+"/"+file
actual_path1=path1+"/"+"train/"+dirname+"/"+file
actual_path2=path1+"/"+"test/"+dirname+"/"+file
img = cv2.imread(actual_path, 0)
bw_image = func(actual_path)
if i<num:
c1 += 1
cv2.imwrite(actual_path1 , bw_image)
else:
c2 += 1
cv2.imwrite(actual_path2 , bw_image)
i=i+1
label=label+1
print(var)
print(c1)
print(c2)