-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd.py
57 lines (47 loc) · 2.3 KB
/
cmd.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
from pixelqueer import *
import cv2
def run(args):
if args.action == "learn":
male_eigenfaces, female_eigenfaces, mtf_matrix, ftm_matrix = learn(args.source, args.maxEigenfaces, args.maxImages)
learn_file = open(args.brain, "wb")
pickle.dump(male_eigenfaces, learn_file)
pickle.dump(female_eigenfaces, learn_file)
pickle.dump(mtf_matrix, learn_file)
pickle.dump(ftm_matrix, learn_file)
elif args.action == "run":
learn_file = open(args.brain, "rb")
male_eigenfaces = pickle.load(learn_file)
female_eigenfaces = pickle.load(learn_file)
mtf_matrix = pickle.load(learn_file)
ftm_matrix = pickle.load(learn_file)
original_image = args.image
altered_image = None
print args.direction
if args.direction == "mtf":
print "MTF Mode"
altered_image = alter_image(male_eigenfaces, female_eigenfaces, mtf_matrix, original_image)
elif args.direction == "ftm":
print "FTM Mode"
altered_image = alter_image(female_eigenfaces, male_eigenfaces, ftm_matrix, original_image)
else:
print "Non-binary gender not yet supported :("
return
cv2.imshow("Altered", altered_image)
cv2.waitKey(0)
if args.out is not None:
altered_image_to_save = Image.fromarray(((altered_image+1.0)/2.0 * 255).astype(np.uint8))
altered_image_to_save.save(args.out)
else:
plot_image(original_image, altered_image)
print "Hello world!"
parser = argparse.ArgumentParser(description="Genderbending!")
parser.add_argument("action", choices=["learn", "run"])
parser.add_argument("brain", help="Destination file for learned data")
parser.add_argument("--source", help="Source image folder containing Male and Female subfolders")
parser.add_argument("--direction", choices=["mtf", "ftm"], help="Direction to bend gender")
parser.add_argument("--maxEigenfaces", help="Maximum number of eigenfaces to use", default=max, type=int)
parser.add_argument("--maxImages", help="Maximum number of images to use (per gender)", default=max, type=int)
parser.add_argument("--image", help="Image to load (run mode only)")
parser.add_argument("--out", help="Output file path")
args = parser.parse_args(sys.argv[1:])
run(args)