color to black and white

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?".
zoran1973

color to black and white

Post by zoran1973 »

Hello everybody!
I try to convert some scanned old shematic to black and white.
When I convert with monocrome option result is bad.
I try with photoshop and option threshold give me very good result but I have more then 200 images :(
Does imagemagick have this options?
This is help for photoshops threshold:
The Threshold command converts grayscale or color images to high-contrast, black-and-white images. You can specify a certain level as a threshold. All pixels lighter than the threshold are converted to white; all pixels darker are converted to black. The Threshold command is useful for determining the lightest and darkest areas of an image.

I try -threshold option (and also ‑black‑threshold and ‑white‑threshold) but result was allways white or same image.
Do you have some option for me?
Thanks in advance
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

try -threshold with percent values. it is easier than using raw 16-bit values if you are on IM Q16.
zoran1973

Re: color to black and white

Post by zoran1973 »

I try this:
from
convert in.jpg -threshold 5% out5.jpg
to
convert in.jpg -threshold 95% out95.jpg
and all out*.jpg are white
What I do wrong?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

nothing, try 99% (you can use decimal fractions, also, eg. 99.9%). but to find out what is happening, you will have to post a link to one of your images.
also saving the result as jpg is not the best as its compression changes the values and you may not end up with pure black and white. try gif. what version of IM are you using? if old, then perhaps upgrade.
zoran1973

Re: color to black and white

Post by zoran1973 »

I try 99 and 99.999% but result is white image. :(
I use ImageMagick-6.4.1-Q16 I think it isn't too old.
I convert to jpg only when testing, I will convert to 2 colors TIFF.
This is my original image:
http://img31.imageshack.us/img31/8769/testkz.jpg
And this is why I wish
http://img207.imageshack.us/img207/3606/photoshopo.jpg
Thank you for your help and time :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

this works for me with IM 6.5.8-2 Q16 (Mac OSX Tiger)

convert testkz.jpg -threshold 60% testkz60.gif

http://www.fmwconcepts.com/misc_tests/testkz60.gif


Perhaps you have a bad version of IM or one where there was a bug. Try upgrading if this does not work for you.
zoran1973

Re: color to black and white

Post by zoran1973 »

I down new version ImageMagick-6.5.8-2-Q16-windows-dll.exe
first deinstall old one, install new, restart whole sistem...
and try your command line
convert testkz.jpg -threshold 60% testkz60.gif
and not working
I try
convert test.jpg -threshold 0% test0.gif
convert test.jpg -threshold 0.999% test0999.gif
convert test.jpg -threshold 1% test1.gif
convert test.jpg -threshold 2% test2.gif
convert test.jpg -threshold 5% test5.gif
convert test.jpg -threshold 10% test10.gif
convert test.jpg -threshold 90% test90.gif
convert test.jpg -threshold 95% test95.gif
convert test.jpg -threshold 99% test99.gif
convert test.jpg -threshold 99.999% test99999.gif
convert test.jpg -threshold 100% test100.gif
and at output all are same - white images

At start I think that I do something wrong but now...I don't know what to do...do you have idea?
It is not so important because I do that thrue photoshop, because I spend more time to resolve this problem, but now this intrigues me.
I have the time, did not press to make this.....

Please try this:
convert test.jpg -channel black -threshold 50 1.jpg
convert test.jpg -channel black -threshold 100 2.jpg
convert test.jpg -channel black -threshold 250 3.jpg
convert test.jpg -channel black -threshold 500 4.jpg
convert test.jpg -channel black -threshold 5 5.jpg
convert test.jpg -channel black -threshold 5000 6.jpg

convert test.jpg -black-threshold 1% -white-threshold 50% 7.jpg
convert test.jpg -black-threshold 5% -white-threshold 50% 8.jpg
convert test.jpg -black-threshold 10% -white-threshold 50% 9.jpg
convert test.jpg -black-threshold 40% -white-threshold 50% 10.jpg
convert test.jpg -black-threshold 80% -white-threshold 50% 11.jpg
convert test.jpg -black-threshold 90% -white-threshold 50% 12.jpg
convert test.jpg -black-threshold 99% -white-threshold 50% 13.jpg
convert test.jpg -black-threshold 100% -white-threshold 50% 14.jpg
convert test.jpg -black-threshold 99.999% -white-threshold 50% 15.jpg
convert test.jpg -black-threshold 0.001% -white-threshold 50% 16.jpg

convert test.jpg -black-threshold 50% -white-threshold 0.001% 17.jpg
convert test.jpg -black-threshold 50% -white-threshold 1% 18.jpg
convert test.jpg -black-threshold 50% -white-threshold 5% 19.jpg
convert test.jpg -black-threshold 50% -white-threshold 10% 20.jpg
convert test.jpg -black-threshold 50% -white-threshold 40% 21.jpg
convert test.jpg -black-threshold 50% -white-threshold 50% 22.jpg
convert test.jpg -black-threshold 50% -white-threshold 80% 23.jpg
convert test.jpg -black-threshold 50% -white-threshold 90% 24.jpg
convert test.jpg -black-threshold 50% -white-threshold 99% 25.jpg
convert test.jpg -black-threshold 50% -white-threshold 99.999% 26.jpg
convert test.jpg -black-threshold 50% -white-threshold 100% 27.jpg

I try and every images on the output are the same like at input
images at input have 531.373kb and at output 531.709 kb but I cant see diferent.
Thank you at your help
zoran1973

Re: color to black and white

Post by zoran1973 »

I try Magic Studio on web and there work....at my computer AND at my work not work.
I don't idea :)
Regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

Are you absolutely sure you do not have any other versions of IM installed anywhere? Did you get any error messages when installing IM?

Did you see the message on the Binary Install page (http://www.imagemagick.org/script/binar ... hp#windows) about:

"If you have any problems, install the Visual C++ 2008 Redistributable Package (x86) or Visual C++ 2008 Redistributable Package (x64). 64-bit Windows requires both packages (x86 & x64)."

type

convert -version

and

convert -list configure



Do you get any error messages when running

convert testkz.jpg -threshold 60% testkz60.gif


Try

convert logo: logo.jpg
convert logo: logo.gif
convert logo: logo.png
convert logo.jpg logo2.gif

Do they look OK?
zoran1973

Re: color to black and white

Post by zoran1973 »

Yes I'm sure. I first make uninstal and then install new version.
And when i run path i have only one path to one, new installed IM.
I install Visual C++ 2008 Redistributable Package now but result is same.
convert -version result:
Version: ImageMagick 6.5.8-3 2009-11-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Features: OpenMP


convert -list configure result:

Path: [built-in]

Name Value
-------------------------------------------------------------------------------
NAME ImageMagick

Path: C:\Program Files\ImageMagick-6.5.8-Q16\config\configure.xml

Name Value
-------------------------------------------------------------------------------
CC vs8
COPYRIGHT Copyright (C) 1999-2009 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST windows-unknown-linux-gnu
LIB_VERSION 0x657
LIB_VERSION_NUMBER 6,5,8,2
NAME ImageMagick
RELEASE_DATE 2009-12-15
VERSION 6.5.8
WEBSITE http://www.imagemagick.org

Path: configure.xml

Name Value
-------------------------------------------------------------------------------
CC vs8
COPYRIGHT Copyright (C) 1999-2009 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
HOST windows-unknown-linux-gnu
LIB_VERSION 0x657
LIB_VERSION_NUMBER 6,5,8,2
NAME ImageMagick
RELEASE_DATE 2009-12-15
VERSION 6.5.8
WEBSITE http://www.imagemagick.org



when I run
convert testkz.jpg -threshold 60% testkz60.gif
there is no error on output...
i have testkz60.gif
this is link to picture
http://img412.imageshack.us/img412/8025/testkz60.gif
It is whole white...

I try
convert logo: logo.jpg
convert logo: logo.gif
convert logo: logo.png
convert logo.jpg logo2.gif
And all looks all right.
I use IM for crop and montage and work excelent.

I'm sorry to waste your time...
Probably I can start new question to staff on forum..
Regards
zoran1973

Re: color to black and white

Post by zoran1973 »

E pur si muove!
I found this
viewtopic.php?f=3&t=7212&p=21881
This
convert input.jpg -white-threshold 88% output.jpg
don't work
but this
convert input.jpg -white-threshold 57825 output.jpg
work....not corectly but it is not white :-D

But this work corectly
convert input.jpg -threshold 38500 out385.jpg
And produce image like yours at 60%. Litle bit strange, because I try number below 10000.

And finaly mistery is revealed
I have expirience with dos batch and after I try this
convert input.jpg -threshold 60%% output.jpg
with double % sign
and work!!!!
Very strange, isn't it
So I have to say big THANK YOU!!! for help me resolve this strange trouble!
And probably you learn something.
Regards!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

You did not mention (or I missed it) that you are on windows. Yes, you need %%. See http://www.imagemagick.org/Usage/windows/
zoran1973

Re: color to black and white

Post by zoran1973 »

No, I'm not specially mentioned that I use windows but I suppose that you know that because I wrote what version I use.
ImageMagick-6.5.8-2-Q16-windows-dll.exe
This is windows version. So plese, receive my apology for your lost time!
I use IM for couple years but only for crop and combine screen shoot from google earth, and there isn't %.
Thank you for your help!!!
Best wishes to you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color to black and white

Post by fmw42 »

No apologies necessary. Sorry I had not noticed your use of Windows earlier.
zoran1973

Re: color to black and white

Post by zoran1973 »

Thanks ;-D
Post Reply