Apply "-compose stereo" over a PNG transparent file

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
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Apply "-compose stereo" over a PNG transparent file

Post by Alexvb6 »

Hi,

I'm having trouble in creating a stereo image with a transparent PNG source file.
My code below returns a stereo image, but on a black background, where I need it on a transparent background.

PS: I prefer to use the 'convert' tool, and not the 'composite' tool.
Using 'convert' is preferable as @fmw42 noted it in another post, because it avoids the need to split the process across multiple tools.
(for reference : viewtopic.php?f=1&t=33152&p=151959&hilit=stereo#p151959)

Additional thought : Would this be related to the bug Found by Fred in this post ? http://www.imagemagick.org/discourse-se ... 93#p152093

Using IM v7.0.7-28 Q16 x64 HDRI

Code: Select all

convert ^
  c:\SOURCE.png ^
  -set colorspace sRGB ^
  -background transparent ^
  -gravity Center -extent 1000x1000 ^
  -write mpr:ExtendedSrcImage +delete ^
  ^
  -alpha Set ^
  -channel RGBCMYKA ^
  -background "rgba(255,255,255,0)" ^
  mpr:ExtendedSrcImage mpr:ExtendedSrcImage ^
  -geometry +15+15 -compose stereo ^
  -composite ^
  -write mpr:StereoImage +delete ^
  ^
  mpr:StereoImage ^
  -trim ^
  c:\DESTINATION.png
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Re: Apply "-compose stereo" over a PNG transparent file

Post by Alexvb6 »

I also have tried to create my own manual Stereoscopy function, based on Fred's (as always) useful suggestion, but without success so far (the Background desperately remains Black, not Transparent) :
(Ref : http://www.imagemagick.org/discourse-se ... hp?t=32209)

Code: Select all

convert ^
c:\SOURCE.png ^
-set colorspace sRGB ^
-alpha Set ^
( -clone 0 -background "rgba(0,0,0,0)" -channel r -separate -roll +15+15 +channel ) ^
( -clone 0 -background "rgba(0,0,0,0)" -channel gb -separate +channel ) ^
-delete 0 ^
-alpha Set ^
-channel RGBCMYK ^
-background "rgba(0,0,0,0)" ^
-combine c:\DESTINATION.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Apply "-compose stereo" over a PNG transparent file

Post by snibgo »

Where do you want transparency to come from? Perhaps from SOURCE.png, but the output will contain only the red, green and blue channels, because those are the channels you selected then combined, not alpha. So we could have:

Code: Select all

convert ^
toes_holed.png ^
-set colorspace sRGB ^
-alpha Set ^
( -clone 0 -background "rgba(0,0,0,0)" ^
  -channel r -separate -roll +15+15 +channel ^
) ^
( -clone 0 -background "rgba(0,0,0,0)" ^
  -channel gba -separate +channel ^
) ^
-delete 0 ^
-alpha Set ^
-channel RGBA ^
-background "rgba(0,0,0,0)" ^
-combine ^
s.png
snibgo's IM pages: im.snibgo.com
Alexvb6
Posts: 49
Joined: 2012-10-12T16:50:15-07:00
Authentication code: 67789

Re: Apply "-compose stereo" over a PNG transparent file

Post by Alexvb6 »

Hi Snibgo,

Your approach is really interesting, altough it does not handle the alpha channel the way "compose" did it.
Maybe trying to create a "manual stereo effect" is not the way to go... my guess is that using "-geometry +15+15 -compose stereo" (as in Point 4 listed below) would be the best bet.

A graphical explanation will be better. I am sorry for not having created it in my original post; I apologize for that !
There will be :
  1. The source image
  2. The expected result, created with the "composite" tool
  3. What your suggestion produces with "convert", where the image is darker (especially on the blue layer)
  4. What I have achieved so far using "convert" : as satisfying than what "compose" produces, except the black background


1. THE SOURCE IMAGE
Image


2. THE EXPECTED RESULT WITH "COMPOSITE"

Code: Select all

composite ^
  -channel RGBCMYK -stereo +15+15 ^
  c:\stereo-source.png ^
  c:\stereo-source.png ^
  c:\stereo-2.png
Image


3. WHAT SNIBGO CODE PRODUCES
Image


4. WHAT I HAVE ACHIEVED USING "CONVERT" : as satisfying than what "COMPOSE" produces, except the black background :

Code: Select all

convert ^
  c:\stereo-source.png ^
  -set colorspace sRGB ^
  -background transparent ^
  -write mpr:ExtendedSrcImage +delete ^
  ^
  -alpha Set ^
  -channel RGBCMYKA ^
  -background "rgba(255,255,255,0)" ^
  mpr:ExtendedSrcImage mpr:ExtendedSrcImage ^
  -geometry +15+15 -compose stereo ^
  -composite ^
  -write mpr:StereoImage +delete ^
  ^
  mpr:StereoImage ^
  c:\stereo-4.png
Image

The main goal is to achieve the "Point 2" using code in "Point 4", and rely on the "convert" tool instead of the "composite tool.
I feel close to it, but... actually not !
Post Reply