Page 1 of 1

How can I convert grayscale image to black&white?

Posted: 2010-10-29T07:27:50-07:00
by macias
Hello,

In theory -depth 1 or -colors 2 should work, but after converting the image (png file) I check it with Gimp and it says, it is grayscale, not indexed mode. So -- how can I convert it to black&white? Using IM of course, not Gimp :-).

Cheers,

Re: How can I conver grayscale image to black&white?

Posted: 2010-10-29T08:17:33-07:00
by indiego
macias wrote:Hello,

In theory -depth 1 or -colors 2 should work, but after converting the image (png file) I check it with Gimp and it says, it is grayscale, not indexed mode. So -- how can I convert it to black&white? Using IM of course, not Gimp :-).

Cheers,
try

-type GrayScale -depth 1

Works for my png graphic.

Greetings, Peter

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T11:56:53-07:00
by macias
Well, it works in sense, that there is an output, but the output is in grayscale, not indexed black&white. I checked it using Gimp.

Just to be sure, I updated ImageMagick to the latest of the latest -- still grayscale (but this time filesize is a bit smaller). But still, the image is not indexed.

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T12:35:16-07:00
by indiego
You are right. How about

-type Palette -depth 1 -define png:color-type=0

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T12:50:56-07:00
by indiego
Sorry, again grayscale (wrong color-type number). This should work (hopefully) :D

-type Palette -define png:color-type=3 -define png:bit-depths=1

BTW: there is a typo in

http://www.imagemagick.org/Usage/formats/#png_write

bit-depth instead of bit-depths

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T13:12:52-07:00
by indiego
This is really not easy. I tested some more and got an indexed 2 colored image with

-type bilevel -define png:color-type=3

This time tested with gimp. Sorry for all the wrong solutions, but I'm a IM beginner. :?

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T13:18:26-07:00
by fmw42
Many of IM's PNG features are not currently working correctly. See viewtopic.php?f=3&t=16490

Re: How can I convert grayscale image to black&white?

Posted: 2010-10-29T23:51:12-07:00
by macias
Indiego, thanks. Now I get the indexed image.

Strange thing though, it is as big as grayscale image (it should be smaller, because now each pixel takes only 1 bit) -- for comparison Gimp is way more efficient. I will look further into those options.

Thanks again!

PS. I used this link:
http://www.imagemagick.org/Usage/formats/#png_write

And testes such options:
-type bilevel -define png:color-type=3 -define png:bit-depth=1

In theory it should work, but instead I get error:
convert: Cannot write image with defined PNG:bit-depth or PNG:color-type.

IM in regard to PNG is broken now indeed.