Removing semi-transparent pixels on greyscale image

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
User avatar
HanFox
Posts: 3
Joined: 2012-11-02T16:13:35-07:00
Authentication code: 67789
Location: UK

Removing semi-transparent pixels on greyscale image

Post by HanFox »

I'm trying to remove the semi-transparent pixels on a greyscale image (http://i.imgur.com/cV08w.png).

However, whatever I try it just goes full black and white.

This is the line I normally use:

Code: Select all

convert inimage.png -channel A -threshold 60%% +channel outimage.png
If I recall correctly I've also tried -alpha off and all sorts just to try and get something vaguely useful.

I have read the documentation and tried other things which I can't remember any more...

So is there a way for me to do this baring in mind I would like the exact same script to work on coloured images, too (but I can always just do them separately at a push).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing semi-transparent pixels on greyscale image

Post by fmw42 »

Either of these work for me on IM 6.8.0.4 Q16 Mac OSX Snow Leopard, though I am not sure what effect you want as a result.

convert cV08w.png -alpha off cV08w_aoff.png

convert cV08w.png -background white -flatten cV08w_flatten_white.png


They are slightly different. So try both and see what you like.
User avatar
HanFox
Posts: 3
Joined: 2012-11-02T16:13:35-07:00
Authentication code: 67789
Location: UK

Re: Removing semi-transparent pixels on greyscale image

Post by HanFox »

Okay, I feel a bit dumb. Doing those commands directly on the images has achieved something close... before I was running them through a script with other commands which must have been messing with the channels.

The only thing is, with my original command and both of yours it's darkening the colours.

Original: http://i.imgur.com/cV08w.png

-alpha off: http://i.imgur.com/8Wa3a.png

-background white -flatten: http://i.imgur.com/wVGtX.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing semi-transparent pixels on greyscale image

Post by fmw42 »

Your image is labeled as sRGB colorspace, but is really grayscale. In IM after 6.7.8.3 grayscale is treated as linear, which will be darker. To get around that so it looks as if sRGB as before, but will be labeled grayscale add -set colorspace RGB

convert cV08w.png -set colorspace RGB -alpha off cV08w_aoff2.png

That works for me to make it lighter again.

See
viewtopic.php?f=4&t=21269
User avatar
HanFox
Posts: 3
Joined: 2012-11-02T16:13:35-07:00
Authentication code: 67789
Location: UK

Re: Removing semi-transparent pixels on greyscale image

Post by HanFox »

Ah ha, awesome :D

In the end to get the correct finished product I used threshold instead of alpha off as I'm trying to clean up the edges:

convert cV08w.png -set colorspace RGB -channel A -threshold 60% -colorspace sRGB cV08w_off.png

Thank you very much for your help fmw42. Very much appreciated.
Post Reply