In the previous article, I tried to create an original random dot stereogram using Python.
-Create an original random dot stereogram (RDS) with Python
I was able to see stereoscopically safely, but I was satisfied just by looking at the circles and texts in 3D. This time I will make something a little cooler.
Last time, the random dot stereogram was displayed in grayscale. This is kind of scary like an old TV sandstorm.
Since Matplotlib
has various color maps other than grayscale, I changed it.
plt.imshow(stereogram, cmap='spring')
The feeling of Sadako disappeared and it became a lot of POP. Good.
Last time, I created a depth map of a 3D pattern with 2 values. This is not deep in many ways. By making the depth map a continuous numerical value, it is possible to adjust the degree to which the solid emerges.
I prepared the following pattern as a trial.
def make_depthmap(shape=(400, 600)):
depthmap = np.zeros(shape, dtype=np.float)
cv2.circle(depthmap, (200, 100), 50, (255 ,255, 255), -1)
cv2.circle(depthmap, (400, 100), 50, (200 ,200, 200), -1)
cv2.circle(depthmap, (300, 200), 50, (155 ,155, 155), -1)
cv2.circle(depthmap, (200, 300), 50, (100 ,100, 100), -1)
cv2.circle(depthmap, (400, 300), 50, (55 ,55, 55), -1)
return depthmap
A pattern that darkens in order of Z from the upper left. Now let's create an RDS.
It's amazing. The degree of popping out changes depending on the darkness of the depth map. I also tried this pattern.
def make_rectangle_depthmap(shape=(400, 600)):
depthmap = np.zeros(shape, dtype=np.float)
for i in range(16):
c = 255 - i * 16
cv2.rectangle(depthmap, (100+i*25, 100), (125+i*25, 300), (c, c, c), -1)
return depthmap
Click here for results
It looks like a staircase. Good.
Next time, I would like to create a depth map from a photo (2D image) so that a normal photo can be viewed stereoscopically. I want to be a random dot stereo glamor.
I wrote a sequel.
Recommended Posts