How to create an anaglyph (stereo image) with modified depth

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?".
lynx_abraxas

How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

Hello!

I created an anaglyph with:

Code: Select all

composite -stereo az239b_a_075_0.0.tif az239b_a_085_10.0.tif az239b_075_085_0-10.anaglyph.2.png
It works nice but how can I apply a horizontal displacement between the red and cyan images to adjust the apparent depth of the scene?
How would one create an anaglyph from scratch with IM? It works with the following but how do I get the displacement in?

Code: Select all

convert  -channel RC az239b_a_075_0.0.tif az239b_a_085_10.0.tif -combine az239b_075_085_0-10.anaglyph.3.png
Any help or hints are very apreciated.
Lynx

PS: What does the rose: mean in one of the example commands:

Code: Select all

convert rose: -separate -swap 0,2 -combine rose_rb_swap.gif
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to create an anaglyph (stereo image) with modified depth

Post by el_supremo »

What does the rose: mean
That is a builtin image. There's also a logo: builtin image.
Try:

Code: Select all

convert rose: rose.jpg
convert logo: logo.jpg
and look at the output images.

See Pseudo Image Formats and the sections which follow at http://imagemagick.org/script/formats.php#pseudo

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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to create an anaglyph (stereo image) with modified depth

Post by el_supremo »

how can I apply a horizontal displacement between the red and cyan images to adjust the apparent depth of the scene
Have a look at the roll command.
You may have to set the -background or -virtual-pixel options before the -roll to get it to fill in with a suitable colour.

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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to create an anaglyph (stereo image) with modified depth

Post by el_supremo »

This is the kind of command I have used to create an anaglyph using "left" and "right" RGB images. I've added a -roll to show how you would use that.

Code: Select all

convert input_l.jpg -channel r -separate -roll +10+0 ( +channel input_r.jpg -separate -delete -3 ) +channel -combine anaglyph.jpg
It separates the red channel from the left image and then rolls it 10 pixels to the left. Then it reads the right image, separates it into R, G and B channels, deletes the red channel and then recombines the left R and the right G and B channels into one image.

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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to create an anaglyph (stereo image) with modified depth

Post by anthony »

el_supremo wrote:
how can I apply a horizontal displacement between the red and cyan images to adjust the apparent depth of the scene
Have a look at the roll command.
You may have to set the -background or -virtual-pixel options before the -roll to get it to fill in with a suitable colour.

Pete
Background and virtual pixels are not used for roll. The image wraps around itself.

You could think of roll as shifting the current 'viewport' or 'window' on a tiled virtual pixel landscape.

that is

Code: Select all

convert image.png  -roll +10+10 result.png
is equivalent to

Code: Select all

convert image.png  -set option:distort:viewport -10-10 \
         -virtual-pixel tile   -distort SRT 0   +repage  result.png
Do if you want to 'roll' but with more control over the pixels that are 'rolled in' use the distort version. Note however that it does more work so would be slower! But not by a huge amount.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create an anaglyph (stereo image) with modified depth

Post by fmw42 »

Whether you use -roll or -distort with viewport control, you will still have edge effects by the amount of shift, where you will not have correspondence between the two images. So either way, you have to live with the edge effects or crop the resulting image to get rid of the distracting edge effects. This would also be similar if you took two photographs that were offset from each other. There would be a small area on one side or the other where the two photographs had different subject material.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to create an anaglyph (stereo image) with modified depth

Post by magick »

We'll add an offset parameter to the stereo anaglyph process for the next point release. We need Anthony to approve an option change-- -stereo becomes -stereo offset. If not we'll need to use something like -define option:stereo:offset=5, for example.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to create an anaglyph (stereo image) with modified depth

Post by anthony »

I have no problem with changing the option. I have not documented or exampled it. It is probably a good thing to do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lynx_abraxas

Re: How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

Thank You all for the much advice. The -stereo option with an offset would be nice. It would probably help newbies if the command-line-options page would tell that this options only works with compsite.

Thanks again
Lynx
lynx_abraxas

Re: How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

Thinking about it, rolling is fine but extending the image by the amount they are displaced would be better. One wouldn't loose anything then.
I tried:

Code: Select all

convert az239b_a_075_0.0.tif -channel r -separate -border  10x0 "(" +channel az239b_a_085_10.0.tif -separate -delete -3 ")" +channel -combine az239b_075_085_0-10.anaglyph.5.png
But I end up with 3 images az239b_075_085_0-10.anaglyph.5-0.png, az239b_075_085_0-10.anaglyph.5-1.png and az239b_075_085_0-10.anaglyph.5-2.png.
Why's that?

Lynx
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create an anaglyph (stereo image) with modified depth

Post by fmw42 »

lynx_abraxas wrote:Thinking about it, rolling is fine but extending the image by the amount they are displaced would be better. One wouldn't loose anything then.
I tried:

Code: Select all

convert az239b_a_075_0.0.tif -channel r -separate -border  10x0 "(" +channel az239b_a_085_10.0.tif -separate -delete -3 ")" +channel -combine az239b_075_085_0-10.anaglyph.5.png
But I end up with 3 images az239b_075_085_0-10.anaglyph.5-0.png, az239b_075_085_0-10.anaglyph.5-1.png and az239b_075_085_0-10.anaglyph.5-2.png.
Why's that?

Lynx
By adding a border to the left image, you have made it a different size than the right image. I do not know how -combine will handle that.

If you really want to pad, then you should pad the left image by half the offset on its left side only and pad the right image by half the offset on its right side only. (I think I have the pad on the correct side on the basis of the direction of roll specified above?) That way the left and right images are offset by the amount you want and are both the same size. See -splice http://www.imagemagick.org/Usage/crop/#splice

But no matter whether you pad using -splice or use -roll, you are still going to have edge effects where the two images do not correspond. In the end, you have to live with these edge effects or crop them off.

The other alternative, is to crop on the right side of the left image and on the left side of the right image, so that the end result is two images the same size, but the effect is that they are offset. Then you have no edge effects. (Again, I hope I have the crop on the correct sides?)

But the bottom line is that no matter how you handle it, you will lose some data on the sides by the amount of the offset.

The last option is to take two images that are photographed with the camera shifted. But you may still have some edge effects that you might want to crop out.
lynx_abraxas

Re: How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

-spice is much better here of corse and using it on both images now results in one output image.
Experimenting a little with the paranthese (as discribed in basic usage) I'm wondering now why this command doesn't yield what I'd expect/want:

Code: Select all

convert \( az239b_a_075_0.0.tif -splice 10x0 \) \( az239b_a_085_10.0.tif -gravity east -splice 10x0 \) -channel RC -combine az239b_075_085_0-10.anaglyph.5.png
There is no red in the resulting image at all.
My images are from a microscope tilt series and are therefor taken at different angles one after another. With these I haven't noticed any edge effect.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create an anaglyph (stereo image) with modified depth

Post by fmw42 »

lynx_abraxas wrote:-spice is much better here of corse and using it on both images now results in one output image.
Experimenting a little with the paranthese (as discribed in basic usage) I'm wondering now why this command doesn't yield what I'd expect/want:

Code: Select all

convert \( az239b_a_075_0.0.tif -splice 10x0 \) \( az239b_a_085_10.0.tif -gravity east -splice 10x0 \) -channel RC -combine az239b_075_085_0-10.anaglyph.5.png
There is no red in the resulting image at all.
My images are from a microscope tilt series and are therefor taken at different angles one after another. With these I haven't noticed any edge effect.
I am not sure why you are using RC for red and cyan? But you are trying to combine 4 channels, 2 from each image. You need to get the red from the left image and the blue and green from the right image.

Try any one of these:

convert left.jpg -channel r -separate -splice 10x0 \
\( +channel right.jpg -gravity east -splice 10x0 -separate -delete -3 \) \
+channel -combine anaglyph.jpg

convert \( left.jpg -splice 10x0 -channel r -separate \) \
\( +channel right.jpg -gravity east -splice 10x0 -separate -delete -3 \) \
+channel -combine anaglyph2.jpg

convert \( left.jpg -splice 10x0 -channel r -separate \) \
\( +channel right.jpg -gravity east -splice 10x0 -channel gb -separate \) \
+channel -combine anaglyph3.jpg

The first two above separate the red from the left and delete the red from the right and combine the remaining 3 channels. The third separates the red from the left and separates the blue and green from the right and combines the remaining 3 channels. (The first one splices 10 pixels on the left of the red channel only. The second splices to all channels of the left and then separates the spliced red channel).
lynx_abraxas

Re: How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

Well, there might be a misunderstanding. The TIFs are grey images (from a TEM) so I assume they only have one channel. That's why I used (as in my first post):

Code: Select all

convert  -channel RC az239b_a_075_0.0.tif az239b_a_085_10.0.tif -combine az239b_075_085_0-10.anaglyph.3.png
One grey image for red and another for cyan/bg (because our "glasses" are red, cyan). I got to that command from the line in the channels examples (http://www.imagemagick.org/Usage/channels/#channels):
As such, even if you use a "-channel BR" setting, "-combine" will expect two images, first the red then the blue. The green and alpha values will be set from the current "-background" setting values.
Because the TIFs are grey I thought I wouldn't need -separate and only one channel option RC (such that -combine only expects two input images but actually puts the second into bg). In the general case where the input images might be coloured I wonder why the +channel is necessary befor the -combine.

It seems my thinking/understanding is flaued some where with the grey input pics...
lynx_abraxas

Re: How to create an anaglyph (stereo image) with modified depth

Post by lynx_abraxas »

I figured out it only works with three grey imput files:

Code: Select all

convert az239b_080725a.075.tif az239b_080725a.085.tif -clone 1  -combine az239b_075_085_0-10.anaglyph.3.png
or with cloning:

Code: Select all

convert az239b_080725a.075.tif -splice 50x0 \( az239b_080725a.085.tif -gravity east -splice 50x0 \) -clone 1  -combine -gravity Center -shave 100x0+0+0 az239b_075_085_0-10.anaglyph.1.png
Why ever that is...
Post Reply