Page 1 of 1

How to make black and white image?

Posted: 2008-05-19T20:04:49-07:00
by Lukas1234
Function monochrome doesnt work since it making it picture look weird.I think proper function will be channel,but i dont know what i need to type exactly.For example in program gimp making black/white picture is called desaturate/lightning

Re: How to make black and white image?

Posted: 2008-05-19T20:27:50-07:00
by fmw42
I am not sure what you mean by "black and white"? Two colors only?

If you want grayscale from color, you can type:

convert <input> -colorspace Gray <output>

or

convert <input> -type Grayscale <output>

These will convert color to gray.

However, if you want two colors only (black and white), then you need to threshold, for example, to select the color where above will be white and below will be black

convert <input> -threshold xx% <output>

where xx is in range 0-100 (for percent)

Re: How to make black and white image?

Posted: 2008-05-20T03:53:21-07:00
by Lukas1234
First command works fine,thank you.

Re: How to make black and white image?

Posted: 2014-06-18T12:41:42-07:00
by JustForThisPost!
And so does the second one!

convert <input> -type Grayscale <output>
works as well, thanks!

Re: How to make black and white image?

Posted: 2014-06-18T13:17:15-07:00
by snibgo
For many other methods, see my page on "Making an image grayscale (monochrome)".

Re: How to make black and white image?

Posted: 2014-06-18T13:45:55-07:00
by fmw42
As snibgo said, there are many ways and types of color to grayscale conversion. For others on Linux, Mac OS or Windows with Cygwin, I have a script call color2gray at the link below and the page shows examples, also.

Some concepts involved are:

1) -colorspace and type of intensity-like channel (http://www.imagemagick.org/script/comma ... colorspace)
2)-grayscale and one of its intensity settings (http://www.imagemagick.org/script/comma ... #intensity and http://www.imagemagick.org/script/comma ... #grayscale)
3) r,g,b color channel mixing using -color-matrix (http://www.imagemagick.org/script/comma ... lor-matrix) or -separate with -poly (http://www.imagemagick.org/script/comma ... s.php#poly)

Re: How to make black and white image?

Posted: 2014-06-18T14:54:01-07:00
by Werty
I like separating to RGB, then make a mean average (-evaluate-sequence mean) of channel R and G, then a mean average of channel G and B, finally a mean average of those two results, RG and GB, gives it more "life" imo.

Here in color, then normal "-type grayscale", then the method mentioned above.
Image

Reason, I guess, is that there is much more green in the world than red, and especially blue, not much blue around if you look, so by adding more green in the grayscale makes it look more natural, if you can call grayscale natural, but again, that just my opinion.

Re: How to make black and white image?

Posted: 2014-06-18T15:24:16-07:00
by fmw42
Werty wrote:I like separating to RGB, then make a mean average (-evaluate-sequence mean) of channel R and G, then a mean average of channel G and B, finally a mean average of those two results, RG and GB, gives it more "life" imo.
Interesting approach.

If I might suggest in the future that you upload 3 separate images rather than one appended one. That makes it easier for the rest of us to download and do comparisons visually or mathematically. Thanks.

Re: How to make black and white image?

Posted: 2014-06-18T16:49:16-07:00
by Werty
fmw42 wrote:
Werty wrote: If I might suggest in the future that you upload 3 separate images rather than one appended one. That makes it easier for the rest of us to download and do comparisons visually or mathematically. Thanks.
Sorry about that :?

Here they are in higher resolution...

Color
http://peecee.dk/uploads/062014/color.png

-type Grayscale
http://peecee.dk/uploads/062014/gray.png

grayRGB
http://peecee.dk/uploads/062014/grayRGB.png

So I do...

convert color.png -channel R -separate R.png
convert color.png -channel G -separate G.png
convert color.png -channel B -separate B.png
convert R.png G.png -evaluate-sequence mean RG.png
convert G.png B.png -evaluate-sequence mean GB.png
Convert RG.png GB.png -evaluate-sequence mean grayRGB.png

Re: How to make black and white image?

Posted: 2014-06-18T17:22:48-07:00
by fmw42
Thanks for separating the images. Here is unix syntax to do it all in one command.

Code: Select all

convert color.png \
\( -clone 0 -channel RG -separate +channel -evaluate-sequence mean \) \
\( -clone 0 -channel GB -separate +channel -evaluate-sequence mean \) \
-delete 0 -evaluate-sequence mean color2gray1.png

Re: How to make black and white image?

Posted: 2014-06-18T17:41:22-07:00
by snibgo
Another way of doing the same thing, Windows BAT syntax:

Code: Select all

%IM%convert color.png ^
  -separate ^
  -poly "0.25,1, 0.5,1, 0.25,1" ^
  g.png
The 3 weights for the R,G,B channels are 0.25, 0.5 and 0.25. These give the same results as the mean of RG and GB means. You can tweak the three numbers, so long as they add to one. (Of even not, if you want.)

Re: How to make black and white image?

Posted: 2014-06-18T18:01:54-07:00
by Werty
Thanks both.

I just sat and starred at the images for 5 mins, and there really is a lot more detail using that method by adding more green, look at the grass and the flowers, more depth and detail.

Also looked at your page snibgo, about grayscale, some interesting results.

Re: How to make black and white image?

Posted: 2014-06-18T18:18:07-07:00
by fmw42
snibgo wrote:Another way of doing the same thing, Windows BAT syntax:

Code: Select all

%IM%convert color.png ^
  -separate ^
  -poly "0.25,1, 0.5,1, 0.25,1" ^
  g.png
The 3 weights for the R,G,B channels are 0.25, 0.5 and 0.25. These give the same results as the mean of RG and GB means. You can tweak the three numbers, so long as they add to one. (Of even not, if you want.)

Nice simplification, snibgo!

Glad to see that some one else finds my suggested -poly command useful.