Page 1 of 1

Problem: convert png all but black to white, convert to tif

Posted: 2009-06-29T00:43:08-07:00
by Alcareru
Hi all.

(Before replying check P.P.S)

Here's a bit more detail to what I'm trying to accomplish. I have a png image that has graphics and text. All relevant text is black and that's all that interestes me so I want to remove everything else. So I do this:

Code: Select all

convert input.png ( +clone -matte -transparent black -fill white -colorize 100% ) -composite output.png
It sort of works. The only problem is that afeter that when I try to convert the resulting png to tif the tif is somehow "corrupted".

Code: Select all

convert output.png -compress None output.tif
IM Display does show the image just fine, but I can't open it in paint nor in the standard windows image viewer, so there must be something funny going on. When I use the identify tool I see that the image changes from 8-bit DirectClass png -> 8-bit PseudoClass png -> 8-bit Grayscale DirectClass tif
Perhaps that's the problem, but I have no idea how to force IM to output the black & white picture as if it was colored.

P.S. Almost the same thing happens if I do things in the opposite order, firts convert to tiff and then remove all but black. The only difference is that it the picture changes from:
8-bit DirectClass png -> 8-bit DirectClass tif -> 1-bit Bilevel DirectClass tif

P.P.S LOL. 2 seconds afeter posting this I came up with yet another thing to try and it worked. I reverserd the order (which was probly irrelevant) and added the trigger -type TrueColor and now it produces nicely working tiffs. I thoght I had tried that already, but perhaps I misspelled TrueColor or had the trigger in wrong place... sry for the ponitless post :)

Re: Problem: convert png all but black to white, convert to tif

Posted: 2009-06-29T03:48:56-07:00
by anthony
All colors but pure black to white.... -threshold 0
See
http://www.imagemagick.org/Usage/quantize/#threshold

OR -fill white +opaque black
The '+' form of opaque means NOT this color

That last can also use a -fuzz factor to say color not 'this close' to black.

See http://www.imagemagick.org/Usage/color/#opaque
and http://www.imagemagick.org/Usage/color/#fuzz

Re: Problem: convert png all but black to white, convert to tif

Posted: 2009-07-02T06:52:58-07:00
by Alcareru
Thanks for the threshold tip. It seems to be quicker than that other method. Can I use it if I want to extract some other color than pure black? Let me specify that question a bit more. Lets say I have a picture that has 3 colors: white, black, green. Now would it be possible to use threshold to convert everything green in to black and everything else to white (including the old black areas)?

Re: Problem: convert png all but black to white, convert to tif

Posted: 2009-07-02T08:53:29-07:00
by fmw42
Alcareru wrote:Thanks for the threshold tip. It seems to be quicker than that other method. Can I use it if I want to extract some other color than pure black? Let me specify that question a bit more. Lets say I have a picture that has 3 colors: white, black, green. Now would it be possible to use threshold to convert everything green in to black and everything else to white (including the old black areas)?

convert inputimage -fill white +opaque green -fill black -opaque green resultimage

Re: Problem: convert png all but black to white, convert to tif

Posted: 2009-07-02T23:08:02-07:00
by Alcareru
fmw42 wrote:
Alcareru wrote:Thanks for the threshold tip. It seems to be quicker than that other method. Can I use it if I want to extract some other color than pure black? Let me specify that question a bit more. Lets say I have a picture that has 3 colors: white, black, green. Now would it be possible to use threshold to convert everything green in to black and everything else to white (including the old black areas)?

convert inputimage -fill white +opaque green -fill black -opaque green resultimage
Thanks. I'm starting to get a hang of this :) Next I have a bit more comclicated question. I'll make new post out of it, though it remotely has something to do with this, but the original topic: "convert png all but black to white, convert to tif" wouldn't really describe it.