Skip to content

Commit 1ce116f

Browse files
committed
image preprocesssion function
1 parent 2615d42 commit 1ce116f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

LinkGAN/preprocess.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import tensorflow as tf
2+
import numpy as np
3+
import io
4+
import os
5+
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
6+
import cv2
7+
from Essential import *
8+
from keras.models import load_model
9+
import pandas as pd
10+
11+
def preprocess(image_path, mod_path, content_to_sketch):
12+
13+
mod = load_model(mod_path)
14+
pd.set_option('display.expand_frame_repr', False)
15+
16+
images = load_image(image_path)
17+
new_path = image_path + '/temp'
18+
19+
for i in range(len(images)):
20+
21+
temp = resize(images[i])
22+
if not os.path.exists(new_path):
23+
os.makedirs(new_path)
24+
name = new_path + '/resized_' + str(i) + '.jpeg'
25+
print name
26+
27+
cv2.imwrite(name, temp)
28+
29+
if content_to_sketch:
30+
images = load_image(new_path)
31+
32+
for i in range(len(images)):
33+
34+
width = float(images[i].shape[1])
35+
height = float(images[i].shape[0])
36+
depth = float(images[i].shape[2])
37+
38+
print images[i].shape
39+
40+
images[i] = images[i].transpose((2, 0, 1))
41+
42+
light_map = np.zeros(images[i].shape, dtype=np.float)
43+
44+
for j in range(3):
45+
light_map[j] = light_map_single(images[i][j])
46+
47+
light_map = normalize_pic(light_map)
48+
light_map = resize_img_512_3d(light_map)
49+
50+
line_mat = mod.predict(light_map, batch_size=1)
51+
line_mat = line_mat.transpose((3, 1, 2, 0))[0]
52+
53+
line_mat = line_mat[0:int(height), 0:int(width), :]
54+
show_active_img_and_save('sketches', line_mat, './' + str(i) + '.jpeg')
55+
line_mat = np.amax(line_mat, 2)
56+
57+
show_active_img_and_save_denoise_filter2('sketches', line_mat, new_path + '/sketch/sketched_' + str(i) + '.jpeg')
58+
show_active_img_and_save_denoise_filter('sketches', line_mat, './' + str(i) + '.jpeg')
59+
60+
sketch_path = new_path + '/sketch'
61+
content_path = new_path
62+
63+
return content_path, sketch_path

0 commit comments

Comments
 (0)