I have the notion that should I ever have children, I will be one of the coolest (read: “geekiest”) dads ever. I will teach my children things like how wine and beer are made, what makes an airplane fly, and why the sky is blue. And even if they should ever precociously ask where babies come from, I will explain it to them in full detail: the same place where beer comes from… “a kit that your mother and I bought at a store.”
Needless to say, I want to foster the spirit of learning and building things. And when we at UPT got a hold of red-and-cyan 3D glasses, I wanted to try making 3D anaglyph images. I can see in my mind’s eye, a child’s voice asking me: “Daddy, where does 3D come from?” It’s very likely that there are already mobile phone apps out there that will generate a 3D anaglyph image for you automatically. But I’d rather not my children learn 3D from the streets, or the media. I rue for the days when sex and violence was all the gimmick that was needed to hook an audience. Now 3D is so ubiquitous, children will be exposed to it at a much earlier age.
We see the world as flat images. Depth is only inferred through context and stereoscopic vision. We merge the slightly dissimilar images from both eyes and in a way, triangulate depth. Try touching the tip of your index fingers with only one eye open. It’s more difficult than with both eyes
With only one image for reference, depth can be very difficult to assess– an illusion that filmmakers can exploit. To create the illusion of depth in films, two images are simultaneously projected onto the screen. Special glasses filter the image so that each eye will see ofsetted images. The brain merges the two images and the illusion of depth is created. Currently, a lot of home theatre set-ups will use an active shutter system, where the lens of the eye piece will quickly alternate on and off in synch with alternating images on the tv set. Movie theaters generally use a passive system where the lens will filter out light.
For the purpose of this tutorial, we’ll be doing it old school with a pair of red-and-cyan anaglyph glasses.
Generate the Images
To create a 3D anaglyph, you will need two images of the same scene taken from slightly offset positions. This will mimic the offset of the human eye. I used my phone camera to take these pictures.
Side by side, the differences are subtle. An animated gif will make their differences apparent. Using two cameras placed side by side with a special mount will minimize errors. I used a single camera, and this requires some manual correction to fix the alignment.
Align the Images
The images need to be aligned. In photoshop, bring both images onto separate layers. Create groups labelled left and right, and place images into their respective group. Change the transparency of the top layer to 50%. This will enable you to see both images and align them.
The image needs to be on the same vertical plane. Find reference lines and use them to align the image vertically. I used the top of Mickey’s ears. This may require rotating or slight resizing the top image.
Pick a focal point and use that to align the image horizontally. The focal point will be relatively aligned, but you will notice that the other elements will be offset. Crop the image to frame it.
An animated gif shows how the newly aligned image will look in 3D. Compare it to the previous animated gif. Alternating blinking your right eye and left eye may also produce an effect like the animated gif.
Create the Image for the Left Eye
Temporarily hide the right image, we’ll be working with the left image first. To create an image that is only visible for the left eye, it must be filtered out by the right lens. The right lens is cyan, therefore a cyan image will be invisible in the right eye, but visible in the left.
The photo above demonstrates how the different lens filter out different colors. To do this, create a gradient map on top of the left eye image. Its color will be from cyan to white. I found it helpful to wear the 3D glasses when selecting the correct shade; it will generally be very close to #00FFFF.
Create the Image for the Right Eye
Unhide the right image. Change its transparency level back to 100%. Create a gradient map for right image, this time from red to white. Again, wearing the glasses will be helpful. It will probably be close to #FF0000. An image that is red will be filtered out by a red lens, and therefore be invisible.
Combine the Image
The final step requires merging the red image with the cyan image. Select the top group, and change its blend option to multiply. It’s important to select the group and not the image itself, since the blend option needs to apply to both the gradient map and the image.
This will produce the final image.
Why the Multiply
For those who are curious about the math involved… Consider the three RGB channels. The red image will range from WHITE, #FFFFFF, (1.0, 1.0, 1.0) to RED, #FF0000, (1.0, 0, 0). Note that the color triplet is expressed as a normalized value instead of an integer. The normalized value can be calculated as VALUE/255. The cyan image will range from WHITE to CYAN (0, 1.0, 1.0).
The multiplication of two color values (R1, G1, B1) and (R2, G2, B2) will equal (R1xR2, G1xG2, B1xB2). RED x CYAN = BLACK. (1.0, 0.0, 0.0) x (0.0, 1.0, 1.0) = (0, 0, 0) or BLACK. Grays are achieved through the multiplication of different intensities of red and cyan. YELLOW (#FFFF00) and BLUE (#0000FF) would also work because they complement each other on the RGB color system the way that RED complements CYAN.
Colors anaglyphs are just as simple to produce. The difference in procedure would be to remove the red output from the left image and the green and blue output from the right image. And instead of multiplying the two images together, you would do an add (or a screen). This preserves the color values from the channels. The math, which is obvious enough if the explanation about color multiply was of interest to you.
Black and white was just how I learned first. And it is a simpler story to tell. And that, children is where 3D comes from. Next time, I’ll tell you how I met your mother.