How to make grayscale anaglyph (stereo) image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
l.a.rabida
Posts: 4
Joined: 2013-04-16T03:44:29-07:00
Authentication code: 6789

How to make grayscale anaglyph (stereo) image

Post by l.a.rabida »

Hi all,

I'm trying to make a grayscale anaglyph image. According to http://arachnoid.com/raytracing/anaglyphic_3d.html, it should work like this:

convert -colorspace gray "left.jpg" "gleft.jpg"
convert -colorspace gray "right.jpg" "gright.jpg"
composite -stereo 0 "gleft.jpg" "gright.jpg" 3d.jpg

But all I get is a completely grayscale output image. I'm not sure if this is a bug or if I'm doing something wrong.

Strangely, using color input does create a color anaglyph:
composite -stereo 0 "left.jpg" "right.jpg" 3d.jpg

I'm using:
Version: ImageMagick 6.7.7-10 2012-08-17 Q16 http://www.imagemagick.org
on Ubuntu (Xubuntu) 12.10.

Thanks in advance for your answer(s)!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to make grayscale anaglyph (stereo) image

Post by el_supremo »

You should be able to create the anaglyph with one command. The -stereo option handles the selection of the correct channels.

Code: Select all

composite left.jpg right.jpg -stereo 0 3d.jpg
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
l.a.rabida
Posts: 4
Joined: 2013-04-16T03:44:29-07:00
Authentication code: 6789

Re: How to make grayscale anaglyph (stereo) image

Post by l.a.rabida »

Thanks for your reply. I just tried the command you gave, and it works, but it creates a colored anaglyph image, not a black and white one. When looking to red/blue glasses, colored anaglyphs are not as pretty as black and white (grayscale) ones. So how should I create grayscale ones? It should be possible according to the website I've given, but the output I get is entirely grayscale, without the red/blue shift.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to make grayscale anaglyph (stereo) image

Post by fmw42 »

That link is creating a colored anaglyph image. Their code is wrong any way, since in IM the input image should be read first and then follow that with -colorspace gray. In more current IM versions, you would likely need to use -set colorspace RGB -colorspace gray

convert leftimage -set colorspace RGB -colorspace gray leftgrayimage
convert rightimage -set colorspace RGB -colorspace gray rightgrayimage
composite -stereo +X leftgrayimage rightgrayimage anaglyphimage

Note, that unless you have created two colored images with stereo offsets in some 3D package or captured two images from shifted vantage points, you must then set an offset using +X, since that is the same image you are using in both cases.

The process of combining them into an anaglyph puts one grayscale image in the red channel and the other grayscale image in the green and blue channels so that you have a red-cyan (colored) anaglyph image.

There is no such thing as a grayscale anaglyph. Anaglyph by definition means color. See http://en.wikipedia.org/wiki/Anaglyph_3D The only way to avoid the coloring process is to use polarize glasses or shuttered glasses. Then the two grayscale or color images can be used. But that cannot be done in Imagemagick.
l.a.rabida
Posts: 4
Joined: 2013-04-16T03:44:29-07:00
Authentication code: 6789

Re: How to make grayscale anaglyph (stereo) image

Post by l.a.rabida »

Thanks for your reply. By "grayscale anaglyph" I mean an anaglyph that is created from two monochrome source images.

I exactly tried your code:

convert leftimage -set colorspace RGB -colorspace gray leftgrayimage
convert rightimage -set colorspace RGB -colorspace gray rightgrayimage
composite -stereo +X leftgrayimage rightgrayimage anaglyphimage

But the resulting "anaglyphimage" is entirely monochrome, there isn't any blue or red in it.

The site http://arachnoid.com/raytracing/anaglyphic_3d.html gives an example of an anaglyph that is created from two monochrome sources, and this should work with ImageMagick to.

So is this a bug or am I still missing something?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to make grayscale anaglyph (stereo) image

Post by fmw42 »

What version of IM are you using and what platform. The following works perfectly fine for me on IM 6.8.4.10 Q16 Mac OSX Snow Leopard.

Image


convert lena.jpg -set colorspace RGB -colorspace gray lena_left.png
Image


convert lena.jpg -set colorspace RGB -colorspace gray lena_right.png
Image


composite -stereo +10 lena_left.png lena_right.png lena_anaglyph.png
Image


Note the above two left/right grayscale images are the same and thus -stereo needs the +10 or whatever you want to use. If you have two images that are taken separately with an offset in position (but not a change in viewing direction), then you can set the +X to +0, because you have a real stereo pair and not just faking it as above.
l.a.rabida
Posts: 4
Joined: 2013-04-16T03:44:29-07:00
Authentication code: 6789

Re: How to make grayscale anaglyph (stereo) image

Post by l.a.rabida »

Thanks for your help! There isn't a PPA available (anymore) for Ubuntu, so I installed the latest version (6.8.4-10 2013-04-13 Q16) of ImageMagick via Wine (that is, the Windows version). Now it does work properly, so I guess it was a bug in the previous version. I've included the version information in my first post.

Thanks again for your answers.
Post Reply