/
check_images.py
48 lines (43 loc) · 1.84 KB
/
check_images.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
from data_input import DataInput
from PIL import Image
import numpy as np
from scipy.misc import imsave
from skimage.exposure import histogram
data_path_faces = "/storage/dataset"
if __name__ == '__main__':
threshold = 700
dataset = DataInput("/storage/dataset", "/storage/dataset_videos/cropped_videos/outputb", "train")
items_faces, items_audio = dataset.get_items()
input_images = np.empty([len(items_faces), 64, 64, 3])
count = 0
index = [0, 3, 6, 8, 9, 17, 21, 29]
references = np.empty(shape=[len(index), 64, 10, 3])
hist_references = np.empty(shape=[len(index), 256])
bins_references = np.empty(shape=[len(index), 257])
ind_count = 0
for ind in index:
reference = Image.open(items_faces[ind])
reference = np.asarray(reference, dtype=float)
reference = reference[:, 0:10, :]
references[ind_count] = reference
hist_reference, bins_reference = np.histogram(reference, bins=256, range=(0, 255))
hist_references[ind_count] = hist_reference
bins_references[ind_count] = bins_reference
ind_count += 1
hist_reference_mean = np.mean(hist_references, axis=0)
bins_reference_mean = np.mean(bins_references, axis=0)
distance = 0
for face in items_faces:
print(count)
input_image = Image.open(face)
input_image = np.asarray(input_image, dtype=float)
input_image_segment = input_image[:, 0:10, :]
hist_input, bins_input = np.histogram(input_image_segment, bins=256, range=(0, 255))
distance = np.sum(np.abs(hist_input - hist_reference_mean))
if distance > threshold:
input_image = np.flip(input_image, axis=1)
name = face.replace('face', 'facechecked')
print(name)
imsave(name, np.asarray(input_image, dtype=int))
input_images[count] = input_image
count += 1