Working with alpha channel

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?".
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Working with alpha channel

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post by lorents »

Thank you so much!
I noticed this solution is not suitable for such images here

Image

How can I fix it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post by snibgo »

What result do you want?
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post by lorents »

I need everything to black under the alpha channel turned white
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post by lorents »

I need to get out of this picture here is

Image

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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.
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post by lorents »

Not quite understand you, if not difficult to please explain in detail.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post by lorents »

Thank you for choosing
I for some reason is obtained as follows

Image

And is it possible to preserve the transparency image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Working with alpha channel

Post 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
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Working with alpha channel

Post 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?
Post Reply