Bringing the third dimension to GMT: Stereograms

Here’s a very simple way to create “3D” stereograms using GMT. The demonstration is for the “cross-eye” method. It is easy enough to make stereograms for the “parallel” method, but supposedly most people find the cross-eye method easier.

The demonstration shows the ocean depth near Tonga, and the Tonga Trench. Without further ado, here is the script:

#!/usr/bin/env zsh

# Create a map viewed from the "left eye".
gmt begin tonga_bathy_left png
   gmt grdview @earth_relief_15s -JQ-177/0/20c -JZ4c \
      -Bwsen -R-179.08/-171.28/-25.68/-14.14/-11000/500 -Cetopo1 -Qi \
      -p190/30/0 -I
gmt end

# Create a map viewed from the "right eye".
gmt begin tonga_bathy_right png
   gmt grdview @earth_relief_15s -JQ-177/0/20c -JZ4c \
      -Bwsen -R-179.08/-171.28/-25.68/-14.14/-11000/500 -Cetopo1 -Qi \
      -p188/30/0 -I
gmt end

# Crop off the edges (so we don't see ugly borders, and so the left and right images
# are exactly the same size). We swap left and right here because we're going to be
# using the "cross-eye" method for our stereograms.
gm convert tonga_bathy_left.png -gravity center -crop 1500x1500+0+0 +repage view_right.png
gm convert tonga_bathy_right.png -gravity center -crop 1500x1500+0+0 +repage view_left.png

# Paste the images beside each other.
gm convert +append view_left.png view_right.png tonga_bathy_stereogram.png

# This should make a red-cyan anaglyph. Need to wait for my glasses to arrive!
#gm composite -stereo view_left.png view_right.png tonga_bathy_anaglyph.png

The trick is to create two grdview images viewed from close together, but not identical viewpoints. In the example I separated the viewpoints by 2 degrees. I initially tried 5 degrees, but found 2 was better. Here is the stereogram:

When trying to bring the 3D image in to “focus” it helps to look at Tongatapu (the large island near the centre of the map) until it sort of merges into one. Once you’ve mastered the technique, it’s possible to see even more detail (or at least the illusion of more detail) than simply looking at the normal 2D grdview image.

But there’s more. Graphics Magick (and Image Magic) can take the left and right stereograms and turn them into a red-cyan anaglyph. That’s what the last commented out line of the script does. However, the etopo1 colour palette wasn’t particularly good for the anaglyph - probably because of the predominance of blues in the image. If the colour palette is changed to gray, then good results are obtained:

2 Likes

I’m, curious to see what this gives with grdview. I think I still have a pair of those glasses in the office.
AFAIK, Anaglyphs have to be made with gray-scale images. In Mirone I have module that computes them grdgradient and some more manipulations. It produces a different image.

1 Like

Looks interesting, but what are the possible use cases?

If you have a pair of those red-cyan glasses you’ll see a nice true 3D image.

Sure, I can read and understand this. But what are possible uses of stereograms for publications or presentations or data analysis?

Sure it might be cool to run a stereo image classroom session, but what features (or what data?) can be highlighted this way?

Plus still images are no longer that cool in the 21s century - compared to 3D movies.

There’s one brain tomography paper cited in the Wikipedia article and one other paper on SEM (scanning electron microscopy) that is not open access. Both are essentially imaging techniques.

I guess it’s just for fun.

There were also 3D movies using anaglyphs … some 70 years ago.

There’s nothing stopping one from making an anaglyph movie - for example a “fly-by” of some interesting geological features or whatever.

It is mostly for fun. I made a few anaglyphs of the area around Tonga, and it was so clear that the Pacific plate was going underneath the Australian plate. I mean 2D maps will show this too, but the third dimension really made it stick out. So I think there’s good educational applications of this, if nothing else. Here is one of my favourite examples, it’s shifted a bit towards the north-east from the previous anaglyph.

Anaglyphs can be in partial colour. There are some nice video clips on YouTube. But I think gray scale is clearest.

1 Like

Tim, your anaglyph works well and fast for me. By fast I mean my brain is quickly fooled in thinking that it’s looking into a real 3D model. Mine (which should have been wider) is slower but gives me a deeper sense of depth.

I think getting the difference in angles between the left and right image is important. I started with a five degree difference. I could make the cross-eye stereogram work for me, but the anaglyph was harder to work. So I dropped the angular difference down to two degrees, and the three dimensions were much easier to see. One degree didn’t work as well as two.

I got the idea to make anaglyphs from a talk I went to at work a week or two ago. Someone presented a rather horrible plot of something, and an audience member said it looked like one of those 3D images. And from that point on I was trapped - I knew I had to try it out! What surprised me was how easy it turned out to be to make them.

What I would to know is what is it really that Graphics Magic does in that operation. I can see a lateral shift of one image with respect to other by some dozens of pixels. But how the combination works out? Remember that the inputs are already 2 RGB images, and there is another RGB at the end.

I don’t know what Graphics Magick does (Image Magick - which Graphics Magick was forked from has a similar operator).

The offset is probably in the two images - they are from slightly different angles. The documentation is brief, and I think wrong:

The left side of the stereo pair is saved as the red channel of the output image. The right side is saved as the green channel. Red-green stereo glasses are required to properly view the stereo image.

I think green should be cyan. There are instructions on how to manually make anaglyph images using tools like Gimp: https://it-s.com/how-to-make-anaglyph-images-in-gimp/ I was initially imagining I’d be able to reproduce the manual methodology using a string of Graphics/Image Magick operators. So imagine my surprise when I found there was already a prebuilt way to do it.

This a lot more than just the difference of 2 slightly different angles, and besides that was already applied to the input images. And the description is wrong in more than the color names. The input is 2 3D (RGB) arrays which gives 6 MxN arrays. Something has to be done to come out with a single RGB image. Maybe the Gimp explains what (haven’t read it yet).

Hmm, from the Gimp page, one just take the red channel of the right-eye image and compose it with the green and blue channels of the left-eye image. Seems simple (but I don’t see any cyan on it).

Well, maybe not.

1 Like

I was just happy to find graphics magick did it on one line, and it worked :grinning_face:

Tim, your Tonga made it to the Julia Forum

1 Like

Nice!

There are some very high resolution bathymetry data from inside the Tonga Trench. I’m not sure if they are in the GEBCO products yet. I’ve got the data sitting in my downloads folder, and I’m contemplating making a movie showing a 3D dive right to the bottom of the trench.

1 Like

That’s a really interesting observation. The angle difference insight is especially useful, two degrees sounds like a great balance for depth without straining the viewer. It’s cool how a casual comment sparked the experiment, and even better that the process turned out to be simpler than expected.