-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-preprocess.py
29 lines (25 loc) · 1.17 KB
/
3-preprocess.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
import numpy as np
import skimage
import skimage.transform
import skimage.feature
import skimage.io
import os
from os.path import join
# train_dir = "copy"
# items = sorted([x for x in os.listdir(train_dir) if x.endswith(".png")], key=lambda x: int(x.split(".")[0]))
# for name in items:
# image = skimage.io.imread(join(train_dir, name), as_grey=True)
# trans = np.where(skimage.filters.gaussian(image, 0.8) > 0.6, 255, 0)
# skimage.io.imsave("copyprocessed/process" + name, trans)
# train_dir = "valid"
# items = sorted([x for x in os.listdir(train_dir) if x.endswith(".png")], key=lambda x: int(x.split(".")[0]))
# for name in items:
# image = skimage.io.imread(join(train_dir, name), as_grey=True)
# trans = np.where(skimage.filters.gaussian(image, 0.8) > 0.6, 255, 0)
# skimage.io.imsave("validprocessed/process" + name, trans)
train_dir = "../3"
items = sorted([x for x in os.listdir(train_dir) if x.endswith(".jpg")], key=lambda x: int(x.split(".")[0]))
for name in items:
image = skimage.io.imread(join(train_dir, name), as_grey=True)
trans = np.where(skimage.filters.gaussian(image, 0.8) > 0.6, 255, 0)
skimage.io.imsave("../3processed/" + name, trans)