Page 1 of 1
Trying to remove all colors except black
Posted: 2015-02-07T17:45:05-07:00
by jswolcott
convert C:\temp\color.tiff -fuzz 10% -fill white -opaque black c:\temp\bw.tiff
The output file is 100% identical to the input.
I'm clearly missing some thing very simple but I haven't the foggiest.
Re: Trying to remove all colors except black
Posted: 2015-02-07T18:14:37-07:00
by jswolcott
Wow. I can not say how much of a dope I feel right now.
Thank you for pointing that out though.
wow
Re: Trying to remove all colors except black
Posted: 2015-02-07T18:37:53-07:00
by jswolcott
Alright, well I do also have imagemagick. I ran this by imagemagick (not graphics magick this time) and replaced the -opaque with a +opaque.
Now I do get changed output. However I'm getting a plain white wash. No black or any thing like it. I also tried the double %% as suggested. Not a windows expert either but we use what we are given eh?
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:04:48-07:00
by fmw42
Upload your tiff image to dropbox.com and put the URL here. We need to see your input so we can test with it. Does it have any alpha transparency?
If you are getting totally white output, perhaps you fuzz value is too large. Try smaller values
What version of Imagemagick are you using? Perhaps it is too old or buggy.
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:36:52-07:00
by snibgo
Code: Select all
convert C:\temp\color.tiff -fuzz 10% -fill white -opaque black c:\temp\bw.tiff
You seem to be running this from the command line.
Don't double the percent sign. The rule about doubling them applies
only to BAT files (scripts).
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:37:51-07:00
by jswolcott
The link is on drive here:
https://drive.google.com/file/d/0B2aTfI ... sp=sharing
should be public
Oh.. Well here is relevant info. It's also outputting this error:
convert.exe: Unknown field with tag 20624 (0x5090) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/857.
convert.exe: Unknown field with tag 20625 (0x5091) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/857.
All I'm trying to do is get all the colors out of this image so that all is left is black, which is primarily text, so I can OCR it.
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:38:47-07:00
by jswolcott
version mageMagick-6.9.0-Q16 windows.
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:47:55-07:00
by glennrp
Try the -threshold option then, e.g., -threshold 30%. Anything darker than 30% intensity becomes black and the rest become white.
e.g.,
Code: Select all
gm convert logo: -colorspace gray -threshold 30% gmbw.png
or
Code: Select all
convert logo: -colorspace gray -threshold 30% imbw.png
Re: Trying to remove all colors except black
Posted: 2015-02-07T19:58:07-07:00
by jswolcott
Well that kind of works. However it keeps a ton of the images which are a dark color but not black... I may be barking up the wrong tree here. I'm just trying to get this simple for tesseract and find a way to automate the process.... cropping is so error prone since the images I'm taking in are not always uniform. -sigh-
Re: Trying to remove all colors except black
Posted: 2015-02-07T20:28:57-07:00
by fmw42
try this
Code: Select all
convert color3.tiff -alpha off -fuzz 35% -fill white +opaque black result.tiff
Adjust the fuzz value as desired. Note you have no pure black in the image. That is why when you use a small fuzz value it shows as pure white.
Re: Trying to remove all colors except black
Posted: 2015-02-07T20:35:28-07:00
by snibgo
"-contrast-stretch" can be useful, eg increase the contrast until 30% of pixels are black and 20% are white:
Code: Select all
convert color3.tiff -contrast-stretch 30,20% t.png
Re: Trying to remove all colors except black
Posted: 2015-02-12T14:08:12-07:00
by jswolcott
Wanted to swing by and say thanks to ya'll. I ended up using
convert color3.tiff -contrast-stretch 35,25% t.png
followed by
convert color3.tiff -alpha off -fuzz 10% -fill white +opaque black result.tiff
Worked perfectly. Removed the color backgrounds entirely and I was then able to crop and OCR the text boxes. Thanks!
Re: Trying to remove all colors except black
Posted: 2015-02-12T14:24:06-07:00
by snibgo
Your first command "convert color3.tiff -contrast-stretch 35,25% t.png" creates t.png. If you don't use t.png, it is pointless.
Re: Trying to remove all colors except black
Posted: 2015-02-12T18:52:14-07:00
by jswolcott
well yeah modified for correct file names. It's inside a script and runs on many images so.. any way. point is it worked.