Page 1 of 2

Working with alpha channel

Posted: 2015-03-15T14:14:08-07:00
by lorents
Good evening!
Tell me, please, in the next issue.

There is the original image with an alpha channel.

Image

Beneath the alpha channel is here is a picture

Image

Tell me, how do I do it like this, while preserving the alpha channel of the image.

Image

Re: Working with alpha channel

Posted: 2015-03-15T14:30:35-07:00
by snibgo
I don't understand what you want. Perhaps:

Code: Select all

convert alfThing.png -alpha off -fill White -opaque Black -alpha on a.png

Re: Working with alpha channel

Posted: 2015-03-15T22:33:09-07:00
by lorents
Thank you so much!
I noticed this solution is not suitable for such images here

Image

How can I fix it?

Re: Working with alpha channel

Posted: 2015-03-15T23:26:44-07:00
by snibgo
What result do you want?

Re: Working with alpha channel

Posted: 2015-03-16T12:00:46-07:00
by lorents
I need everything to black under the alpha channel turned white

Re: Working with alpha channel

Posted: 2015-03-16T12:29:14-07:00
by lorents
I need to get out of this picture here is

Image

Image

Re: Working with alpha channel

Posted: 2015-03-16T13:51:16-07:00
by snibgo
The following gives the coordinates of the "bird" image:

Code: Select all

convert bird.png -alpha off -format "%@" info:
From the result, a script can do the rest of the work.

Re: Working with alpha channel

Posted: 2015-03-16T14:17:00-07:00
by lorents
Not quite understand you, if not difficult to please explain in detail.

Re: Working with alpha channel

Posted: 2015-03-16T16:10:00-07:00
by snibgo
The result you want has some pixel colours smeared to the left and right (shown in red), and others are not smeared (shown in green).

What rules say which should be smeared, and which should not?
Image

Re: Working with alpha channel

Posted: 2015-03-16T23:05:27-07:00
by lorents
Here is an image without blurring with a white background

Image

As can be seen the black is present there originally, and that's how to determine that relate to image blur, and what does not define apparently did not happen.

Re: Working with alpha channel

Posted: 2015-03-17T23:02:12-07:00
by snibgo
This smearing effect could easily be done in a process module: loop through the lines; in each line, find the first non-white pixel, copy its values to the white pixels on the left, and similarly for the right-hand side.

I can't see an easy way of doing it at the command-line. It could be done with a complex script that used the same method.

Or a command might build a displacement map, as shown in http://im.snibgo.com/ckbkClut.htm#graph .

Or the white pixels could be made transparent, and a small blur would smear the visible pixels sideways. Repeat until no transparency remains. This method would be imprecise, and slow.

Someone else may have a better method.

Re: Working with alpha channel

Posted: 2015-03-18T00:16:42-07:00
by snibgo
Or we can repeatedly compose over, shifting the bottom image slightly. Windows BAT syntax:

Code: Select all

convert ^
  birdBkW.png ^
  -transparent White ^
  -compose DstOver ^
  ( -clone 0 ) -geometry +1+0 -composite ^
  ( -clone 0 ) -geometry +2+0 -composite ^
  ( -clone 0 ) -geometry +4+0 -composite ^
  ( -clone 0 ) -geometry +8+0 -composite ^
  ( -clone 0 ) -geometry +16+0 -composite ^
  ( -clone 0 ) -geometry +32+0 -composite ^
  ( -clone 0 ) -geometry +64+0 -composite ^
  ( -clone 0 ) -geometry +128+0 -composite ^
  ( -clone 0 ) -geometry -1+0 -composite ^
  ( -clone 0 ) -geometry -2+0 -composite ^
  ( -clone 0 ) -geometry -4+0 -composite ^
  ( -clone 0 ) -geometry -8+0 -composite ^
  ( -clone 0 ) -geometry -16+0 -composite ^
  ( -clone 0 ) -geometry -32+0 -composite ^
  ( -clone 0 ) -geometry -64+0 -composite ^
  ( -clone 0 ) -geometry -128+0 -composite ^
  -background White -compose Over -layers flatten ^
  birdtw.png
birdBkW.png:
Image
birdtw.png
Image

Re: Working with alpha channel

Posted: 2015-03-18T12:28:45-07:00
by lorents
Thank you for choosing
I for some reason is obtained as follows

Image

And is it possible to preserve the transparency image

Re: Working with alpha channel

Posted: 2015-03-18T12:40:38-07:00
by snibgo
What was your exact command? What version of IM are you using? I use v6.9.0-0.


The input file, birdBkW.png, has no transparency.

You could copy the transparency from an image that has transparency:

Code: Select all

convert ^
  birdBkW.png ^
  birdWithTrans.png ^
  -compose CopyOpacity -composite ^
  smearedWithTrans.png

Re: Working with alpha channel

Posted: 2015-03-18T12:55:59-07:00
by lorents
Figured out, I just used, that this image

Image

And you can use the above image, to obtain the same result

Image

But at the same time that the layer alpha channel is preserved?