Page 1 of 1

One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T05:58:51-07:00
by biospud
I know I can create red-cyan anaglyph images by

Code: Select all

composite -stereo +0 right.png left.png stereo.png
...but now I want to create green-magenta anaglyphs. Specifically I want to combine the green color channel from the left-eye image, with the red and blue channels from the right-eye image, to create a full color green-magenta stereo 3D anaglyph. Oh, and I would prefer to do it with a single ImageMagick command, because I need to process tens of thousands of images (video frames), and I am worried about disk space and the tedium of cleaning up intermediate files.

Can anyone suggest a one-liner for this process? If not, how about process with a minimum of intermediate files?

Regards,
Christopher

Re: One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T09:42:09-07:00
by fmw42
Try this. I am not sure if the roll should be positive or negative, but you can try each. I have assumed that your images are color. If they are grayscale already, then the -colorspace gray is not needed


convert \( right -colorspace gray -roll +5+0 \) \( left -colorspace gray \) \( right -colorspace gray -roll +5+0 \) -combine result

If on windows, then remove all the \


This also assumes that you are using a very current IM. Otherwise, see viewtopic.php?f=4&t=21269

Re: One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T10:27:06-07:00
by biospud
Thank you very much fmw42; this is definitely a step in the right direction. However it's not yet exactly what I need.

First, for my purposes, the "roll" statements are unnecessary; my left-eye and right-eye views are already correctly aligned and require no additional depth adjustment. But it's great that you included them there, for others who might read this thread and who have different needs.

More importantly, your recommended command line converts each image to grayscale, then converts those intensities to the output color channels. Believe me, I understand why you would recommend that approach. But I was not kidding when I said I want to extract the green channel from the left image, and the red and blue channels from the right image, and then combine those channels into the synthetic image. There is a big difference between 1) extracting the green channel from an image, and 2) converting an image to grayscale and coloring the result green. I wish to do the former, i.e. extracting three out of the six actual original color channels, to create a so-called "full color" anaglyph.

Is there an alternate command line like this that would truly yield the distinct color channels from each image?

Thanks again fmw42 for sharing your expertise.

Regards,
Christopher

Re: One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T11:15:57-07:00
by biospud
I eventually got it working. I can produce a full color green-magenta anaglyph image from the individual left and right full color images thus:

Code: Select all

convert \(right -set colorspace RGB -fx R \) \(left -set colorspace RGB -fx G \) \(right -set colorspace RGB -fx B \) -combine result
For some reason I needed to add the "-set colorspace RGB" stanzas, otherwise the output image would be subject to an unwanted dramatically darkening gamma adjustment.

Regards,
Christopher

Re: One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T11:23:47-07:00
by fmw42
This should be faster than using -fx


convert \( right -set colorspace RGB -channel r -separate +channel \) \( left -set colorspace RGB -channel g -separate +channel \) \( right -set colorspace RGB -channel b -separate +channel \) -combine result


You are likely on a version of IM that used linear channels. Thus you need to use -set colorspace RGB to "trick" IM into thinking the channels are already linear so that it does not do the non-linear (sRGB) to linear (RGB) conversion and leaves the channels as sRGB. See the link I put above.

It is always a good idea when asking questions on the forum to report the IM version and platform. Answers can them be more correct as they may depend on the version of IM using and platform.

It may be faster to read the input images only once and use clones.

convert left right \( -clone 1 -set colorspace RGB -channel r -separate +channel \) \( -clone 0 -set colorspace RGB -channel g -separate +channel \) \( -clone 1 -set colorspace RGB -channel b -separate +channel \) -delete 0,1 -combine result

Re: One-liner to create green-magenta anaglyph 3D?

Posted: 2013-09-18T11:37:39-07:00
by biospud
fmw42 said:
convert \( right -set colorspace RGB -channel r -separate +channel \) \( left -set colorspace RGB -channel g -separate +channel \) \( right -set colorspace RGB -channel b -separate +channel \) -combine result
Thanks. That does seem faster than my -fx version.
It is always a good idea when asking questions on the forum to report the IM version and platform. Answers can them be more correct as they may depend on the version of IM using and platform.
Too little too late, but here is my version information anyway (on 64-bit Windows 7):

Code: Select all

$ convert -version
Version: ImageMagick 6.8.4-8 2013-04-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
Thanks again fmw42! You have saved me so much time. Much appreciated.

Regards,
Christopher