title: How to create random-dot stereogram (RDS)?
body: <p>I am trying to understand and code a python script that create a <strong>random-dot stereogram (RDS)</strong> from a depthmap and a random-dot generated pattern. From what I've understood, to create the illusion of depth, pixels are shifted so when we make them merge by changing focus the difference of shifting creates the illusion.</p>
  
  <p>I put this into practice with <strong>this depth map</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/7tBip.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7tBip.jpg" alt="depth map star"></a></p>
  
  <p>Here is <strong>the result:</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/rigEV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rigEV.png" alt="enter image description here"></a></p>
  
  <p>But I don't understand why I can see on the result 2 objects, 1 star "close" to me and an other star "far" from me. And there is different possible results depending of how I focus my eyes.</p>
  
  <p>I have read many things on the subject but I don't get it. Maybe the problem is my poor english or understanding of what I've read but I will appreciate some detailed explanations since there not that much technical explanations on the web about how to code this from scratch.</p>
  
  <p><strong>Note:</strong> I have tried with different size on shift and pattern and it doesn't seem to change anything</p>
  
  <p><strong>Code:</strong> (Tell me if you need other part of the code or some comment about how it work. I didn't clean it yet)</p>
  
  <pre><code>import os, sys
  import pygame
  
  def get_linked_point(depthmap, d_width, d_height, sep):
      """
      In this function we link each pixel in white in the depth map with the 
      coordinate of the shifted pixel we will need to create the illusion
      ex: [[x,y],[x_shifted,y]]
  
      :param sep: is the shift value in pixels
      """
      deptharray = pygame.PixelArray(depthmap)
      list_linked_point = []
      for x in range(d_width):
          for y in range(d_height):
              if deptharray[x][y] != 0x000000:
                  list_linked_point.append([[x, y], [x+sep, y]])
      del deptharray
      return list_linked_point
  
  
  def display_stereogram(screen, s_width, pattern, p_width, linked_points):
      """
      Here we fill the window with the pattern. Then for each linked couple of 
      point we make the shifted pixel [x_shifted,y] equal to the other one 
      [x,y]
      """
      x = 0
      while x &lt; s_width:
          screen.blit(pattern, [x, 0])
          x += p_width
      pixAr = pygame.PixelArray(screen)
      for pair in linked_points:
          pixAr[pair[0][0], pair[0][1]] = pixAr[pair[1][0], pair[1][1]]
      del pixAr
  </code></pre>