What's particularly interesting is that each of the two images is actually two-dimensional but your brain makes "informed guesses" that three dimensions are important, adds a third dimension, and does so differently for each of the two images. The brain uses lots of different hints in combination to guess at three dimensional location (see Depth Cues). In this case, the differences in apparent three dimensional location have to do with the locations of the shadows of the balls. You can demonstrate this for yourself in the figure below. Drag the shadows around by clicking on them and see what you're brain perceives.