Page 1 of 1

Remove black (add transparency)

Posted: 2013-07-22T12:37:48-07:00
by Marcel71
Hi everybody,

Does anybody know if it is possible with imagemagick to remove the black part and that the white stripes also become semi transparent?
Image

I searched, but could not find a 'ready to use' convert command...

Regards,
Marcel

Re: Remove black (add transparency)

Posted: 2013-07-22T12:47:13-07:00
by GreenKoopa
I can't see your image or otherwise connect to that domain.

Re: Remove black (add transparency)

Posted: 2013-07-22T13:07:22-07:00
by Marcel71
That is strange. I see the image an i can connect to glitterbase.com

But okay, i uploaded the image to imgur :)

Image

Re: Remove black (add transparency)

Posted: 2013-07-22T13:20:09-07:00
by GreenKoopa
Do you want?
  • black becomes fully transparent
  • white stays white and fully opaque
  • grays stay gray and become partially transparent
Or something a little different? I ask because the lightest pixel is very dark and so would be less than half transparent.

Re: Remove black (add transparency)

Posted: 2013-07-22T13:22:51-07:00
by fmw42
is this what you want?

convert 6SyqTgj.png \( +clone -fill white -colorize 100 \) +swap -alpha off -compose copy_opacity -composite test1.png

or

This will make the white more opaque by a factor of 2. You can change that value for more opaque if you want.

convert \( 6SyqTgj.png -evaluate multiply 2 \) \( +clone -fill white -colorize 100 \) +swap -alpha off -compose copy_opacity -composite test2.png


I am taking your grayscale image, multiplying it by some factor, then cloning it and filling it completely with white, then putting modified grayscale image into the alpha channel of the white image.

Re: Remove black (add transparency)

Posted: 2013-07-22T13:38:50-07:00
by Marcel71
I would like that the black turns transparent and the white becomes semi transparent. (so there is nothing black anymore, just white semi transparent stripes).

*Will try fmw's solution. Did not see that before posting this :)

Re: Remove black (add transparency)

Posted: 2013-07-22T13:52:49-07:00
by Marcel71
This left me with an empty canvas

Code: Select all

convert 6SyqTgj.png \( +clone -fill white -colorize 100 \) +swap -alpha off -compose copy_opacity -composite test1.png
This looks indeed what i want, i will need to play with the multiply (like set it to 3 or higher) to get the correct result.

Code: Select all

convert \( 6SyqTgj.png -evaluate multiply 2 \) \( +clone -fill white -colorize 100 \) +swap -alpha off -compose copy_opacity -composite test2.png
Thanks a lot fer helping out.

Regards,
Marcel

Re: Remove black (add transparency)

Posted: 2013-07-22T14:17:02-07:00
by GreenKoopa
Marcel71,
An alternative to -evaluate multiply is -auto-level, which would apply a multiply of 3.5 in this case.

Fred,
I had a different solution in mind but I only ran into problems. Any insight?

These create proper output as viewed by IM, but GIMP doesn't show a histogram for them, which couldn't be weirder.

Code: Select all

convert 6SyqTgj.png -alpha Copy out1.png
convert 6SyqTgj.png -alpha Copy PNG32:out2.png
Here -colorize removes the alpha, which seems incorrect.

Code: Select all

convert 6SyqTgj.png -alpha Copy -fill white -colorize 100 out3.png

Re: Remove black (add transparency)

Posted: 2013-07-22T15:41:36-07:00
by fmw42
convert 6SyqTgj.png -alpha Copy out1.png
That should work, but the alpha channel will only have partial transparency and background will have very dark areas under the transparency. So it will all appear dark.

The histogram will have very small bins especially when weighted with the alpha channel. In GIMP histogram change the selector to Alpha and you will see very small bins even in just the alpha channel. Because there is such a large bin at black all the other bins are scaled very small.


But try

convert 6SyqTgj.png -alpha Copy -alpha off -fill white -colorize 100 -alpha on out1.png

That should be the same as my first result which puts a full white image under the alpha channel.

Re: Remove black (add transparency)

Posted: 2013-07-22T22:02:56-07:00
by anthony
You are all making it more complicated than it really is... ;-)

Just use it as a transparency mask for a white image... (or black if that is what you want).

Code: Select all

convert 6SyqTgj.png -background white -alpha shape rain_overlay.png
you can also level adjust before hand if you like to make the rain streaks stronger.

Code: Select all

convert 6SyqTgj.png -auto-level -background white -alpha shape rain_overlay.png