-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpreprocess_dataset.py
More file actions
32 lines (27 loc) · 955 Bytes
/
Copy pathpreprocess_dataset.py
File metadata and controls
32 lines (27 loc) · 955 Bytes
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
#########################################################################################
#################### Script to prepare dataset (pre-processing) ########################
#########################################################################################
# import libs
import cv2
import numpy as np
from matplotlib import pyplot as plt
# high-pass filter kernel
kernel = np.array(
[[-1, 2, -2, 2, -1],
[2, -6, 8, -6, 2],
[-2, 8, -12, 8, -2],
[2, -6, 8, -6, 2],
[-1, 2, -2, 2, -1]])
# input dir
input_dir = 'cover_128/'
# loop images
for x in xrange(1, 1700):
# read img from the input dir
img = cv2.imread(input_dir + str(x) + '.jpg')
# resize img
img = cv2.resize(img, (128, 128), interpolation=cv2.INTER_CUBIC)
# filter the img
dst = cv2.filter2D(img, -1, kernel)
# save image in the output dir
cv2.imwrite('dataset/test/cover/' + str(x) + '.jpg', dst)
print(x)