-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyStereogram.py
More file actions
77 lines (63 loc) · 1.98 KB
/
PyStereogram.py
File metadata and controls
77 lines (63 loc) · 1.98 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#Imports
from PIL import Image
import numpy as np
import sys
TILESIZE=50
#Get input
depthImName = sys.argv[1:2]
if depthImName == []:
depthImName = input("Depthmap? ")
depthImName = ("Depth.png" if depthImName == "" else depthImName)
else:
depthImName = depthImName[0]
#Open depthmap
try:
depth = np.array(Image.open(depthImName))
except FileNotFoundError:
depth = np.array(Image.open("Input/" + depthImName))
print("Creating tile...")
import MakeBG
MakeBG.main(TILESIZE,depth.shape[1::-1])
print("Opening images...")
base = np.array(Image.open("BaseAuto.png"))
assert base.shape[:2] == depth.shape[:2], "Base and depthmap differ in size."
print("Creating arrays...")
depth -= depth.min()
depth = depth * ((TILESIZE / 3) / depth.max())
#depth = (depth * -1) + (depth.max())
diffmap = []
newImage = []
for i in range(base.shape[1]):
diffmap.append([0] * base.shape[0])
newImage.append([0] * base.shape[0])
print("Calculating shift...")
for x in range(len(diffmap)-1,-1,-1):
for y in range(len(diffmap[0])):
tmp = depth[y][x][0]
if x < len(diffmap) - ((TILESIZE) + int(tmp)):
tmp += diffmap[x+(TILESIZE)-int(tmp)][y]
diffmap[x][y] = int(tmp)
print("Creating images...")
for x in range(len(diffmap)-1,-1,-1):
for y in range(len(diffmap[0])):
newImage[x][y] = tuple(base[y][(x-diffmap[x][y]) % base.shape[1]])
def bound(n):
return int(
(
((n + (TILESIZE/2)) % TILESIZE) - (TILESIZE/2)
) * 255/TILESIZE
)
difflist = []
for i in range(len(diffmap[0])):
difflist += [(-bound(diffmap[j][i]), bound(diffmap[j][i]), 0) for j in range(len(diffmap))]
img = Image.new('RGB', (len(diffmap), len(diffmap[0])))
img.putdata(difflist)
img.save('trueDepth.png')
del difflist
im = []
for i in range(len(diffmap[0])):
im += [newImage[j][i] for j in range(len(diffmap))]
img = Image.new('RGB', (len(diffmap), len(diffmap[0])))
img.putdata(im)
img.save('Output/%s' % depthImName.split("/")[-1])
print("Done!")