Page 1 of 2

problem with transparency in composite command

Posted: 2008-09-18T09:05:33-07:00
by ghost
Hi,

I use a composite command with displacement map: composite map.png 1.png +matte -displace 0x30 2.png
1.png has transparent areas, but in 2.png all areas, that should be transparent, becomes black. How can I solve this problem?

Re: problem with transparency in composite command

Posted: 2008-09-18T10:28:49-07:00
by fmw42
I am not sure about transparency handling in -displace as that may not work or be very tricky due to the values in the transparency channel, but you can try adding -channel rgba before -matte NOT +matte. Note +matte turns off the alpha/transparency channel. If that does not work, hopefully Anthony can clarify. So write back and let us know if it works and so that he will see your reply.

Also be sure that map.png is single channel, so replace map.png with \( map.png -channel g \)

composite \(map.png -channel g \) \( 1.png -channel rgba -matte \) -displace 0x30 2.png


If this does not work, you may be able to handle it using the slower -fx. See viewtopic.php?f=1&t=12015

Re: problem with transparency in composite command

Posted: 2008-09-19T02:22:26-07:00
by ghost
Thanks a lot, but in this way it also does not work properly. With composite command I have such problem as htvu in that topic - image id not distorted, only shifted by Y on 30px.

And when I use -fx, distortion strongly differs from what is carried out by 'composite':

1.png
Image

map.png
Image

composite map.png 1.png -displace 0x30 2.png
Image

composite map.png -channel g 1.png -channel rgba -matte -displace 0x30 2.png
Image

convert 1.png map.png -channel RGBA -fx \"p{i,v.g*h}\" 2.png
Image

Re: problem with transparency in composite command

Posted: 2008-09-19T10:06:20-07:00
by fmw42
composite map.png -channel g 1.png -channel rgba -matte -displace 0x30 2.png
You may need to use the parentheses as I originally specified to ensure that each image uses the channel(s) required. If this does not work, then possibly -displace cannot handle transparency. But I will defer to Anthony on that.

composite \( map.png -channel g \) \( 1.png -channel rgba -matte \) -displace 0x30 2.png

see
http://www.imagemagick.org/Usage/basics/#parenthesis

If you are on Windows, then see also
http://www.imagemagick.org/Usage/api/#windows
as Windows uses different conventions and the parentheses don't need the \ escape
convert 1.png map.png -channel RGBA -fx \"p{i,v.g*h}\" 2.png
This was meant only as an example of one particular distortion and shows how to handle the transparency. You need to build your own -fx expression to do the distortion as you need it. But you see it does work with transparency.

Re: problem with transparency in composite command

Posted: 2008-09-21T17:43:59-07:00
by anthony
ghost wrote:Thanks a lot, but in this way it also does not work properly. With composite command I have such problem as htvu in that topic - image id not distorted, only shifted by Y on 30px.

And when I use -fx, distortion strongly differs from what is carried out by 'composite':
The -fx version you are using is doing an absolute distortion. -displace is doing a relative distortion. The results is naturally quite different. You were just lucky they weren't far more different than that you actually achieved.

See http://www.imagemagick.org/Usage/distorts/#lut
for a general introduction to the two different methods.

Re: problem with transparency in composite command

Posted: 2008-09-22T02:40:28-07:00
by ghost
fmw42 wrote:You may need to use the parentheses as I originally specified to ensure that each image uses the channel(s) required. If this does not work, then possibly -displace cannot handle transparency. But I will defer to Anthony on that.
I use it, under Windows, but brackets doesn't do any effect in this expression.

Thank you for your help, but I have already found a Barrel distortion, that gives an effect very similar to my needs :)

Re: problem with transparency in composite command

Posted: 2008-09-22T11:00:31-07:00
by fmw42
ghost wrote:[
Thank you for your help, but I have already found a Barrel distortion, that gives an effect very similar to my needs :)
IM as of 6.4.2-4 already has a barrel distortion. see http://www.imagemagick.org/Usage/distorts/#barrel

Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html

Re: problem with transparency in composite command

Posted: 2008-09-23T03:09:29-07:00
by ghost
fmw42 wrote:IM as of 6.4.2-4 already has a barrel distortion. see http://www.imagemagick.org/Usage/distorts/#barrel
Yes, I also meant this, and use now :)
Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html
Thanks, I downloaded Texteffect but in my Windows under Cygwin it doesn't work :(

Re: problem with transparency in composite command

Posted: 2008-09-23T09:16:47-07:00
by fmw42
Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html
Thanks, I downloaded Texteffect but in my Windows under Cygwin it doesn't work
Can you tell me where and or how it is failing? Does your Cygwin include the bc calculator?

What was your command line for using my texteffect?

It might be an IM version issue? But I would need to know what you were doing to check that.

Re: problem with transparency in composite command

Posted: 2008-09-24T03:57:29-07:00
by ghost

Code: Select all

$ texteffect -t "SOME CONVEX TEXT" -s outline -e convex -d 0.35 -f Arial -p 48 -c skyblue -b white -o black -l 1 -u lightpink test.png
/usr/bin/texteffect: line 825: [: : integer expression expected
I use 6.4.3. bc installed.

Re: problem with transparency in composite command

Posted: 2008-09-24T11:05:42-07:00
by fmw42
Hello Ghost,
ghost wrote:

Code: Select all

$ texteffect -t "SOME CONVEX TEXT" -s outline -e convex -d 0.35 -f Arial -p 48 -c skyblue -b white -o black -l 1 -u lightpink test.png
/usr/bin/texteffect: line 825: [: : integer expression expected
I use 6.4.3. bc installed.

Thanks for the reply and notification. However, this line simply refers to a test of the IM version. But it requires the use of SED. Does your Cygwin include SED?

Try this:

im_version=`convert -list configure | \
sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`
echo "im_version=$im_version"

It should give something like:

im_version=06040308


Let me know what you get from this test. I suspect you do not have SED and so am getting an empty string for the result. Therefore the test of your version against the threshold version for using -distort vs -fx is giving an error.

Fred

Re: problem with transparency in composite command

Posted: 2008-09-25T02:25:49-07:00
by ghost
Hm, it gives an empty string, but I have SED 4.1.5-2 in my Cygwin :/

Re: problem with transparency in composite command

Posted: 2008-09-25T10:03:46-07:00
by fmw42
ghost wrote:Hm, it gives an empty string, but I have SED 4.1.5-2 in my Cygwin :/
Very strange. Can you try other SED commands? Perhaps part of this SED command is not valid for your version of Cygwin SED?

Try removing the \ and make it one long line?

im_version=`convert -list configure | sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`

Also try the following, which replaces SED with GREP, etc. I can change the script to substitute this, if it works for you.

im_version="0$(convert -list configure | grep 'LIB_VERSION_NUMBER' | cut -d\ -f2 | tr ',' '0')"
echo "$im_version"

or

im_version="0`convert -list configure | grep 'LIB_VERSION_NUMBER' | cut -d\ -f2 | tr ',' '0'`"
echo "$im_version"

Re: problem with transparency in composite command

Posted: 2008-09-25T18:06:10-07:00
by anthony
Just a word of caution. I do not recommend that 'grep' solution as it assumes that each of the version/patch numbers will be a single digit. That has not and probably will NOT always be the case, though it usually is.

Re: problem with transparency in composite command

Posted: 2008-09-25T18:50:29-07:00
by fmw42
anthony wrote:Just a word of caution. I do not recommend that 'grep' solution as it assumes that each of the version/patch numbers will be a single digit. That has not and probably will NOT always be the case, though it usually is.

Good point. I had not thought of that, but have seen some minor version numbers above 9.