How to make black and white image?

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

How to make black and white image?

Postby Lukas1234 » 2008-05-19T20:04:49+00:00

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
Lukas1234
 

Re: How to make black and white image?

Postby fmw42 » 2008-05-19T20:27:50+00:00

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)
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make black and white image?

Postby Lukas1234 » 2008-05-20T03:53:21+00:00

First command works fine,thank you.
Lukas1234
 

Re: How to make black and white image?

Postby JustForThisPost! » 2014-06-18T12:41:42+00:00

And so does the second one!

convert <input> -type Grayscale <output>
works as well, thanks!
JustForThisPost!
 
Posts: 1
Joined: 2014-06-18T12:39:50+00:00

Re: How to make black and white image?

Postby snibgo » 2014-06-18T13:17:15+00:00

For many other methods, see my page on "Making an image grayscale (monochrome)".
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3987
Joined: 2010-01-23T23:01:33+00:00

Re: How to make black and white image?

Postby fmw42 » 2014-06-18T13:45:55+00:00

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)
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make black and white image?

Postby Werty » 2014-06-18T14:54:01+00:00

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.
Windows 7 user
Werty
 
Posts: 58
Joined: 2010-08-06T05:37:36+00:00

Re: How to make black and white image?

Postby fmw42 » 2014-06-18T15:24:16+00:00

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.
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make black and white image?

Postby Werty » 2014-06-18T16:49:16+00:00

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
Windows 7 user
Werty
 
Posts: 58
Joined: 2010-08-06T05:37:36+00:00

Re: How to make black and white image?

Postby fmw42 » 2014-06-18T17:22:48+00:00

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
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: How to make black and white image?

Postby snibgo » 2014-06-18T17:41:22+00:00

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.)
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3987
Joined: 2010-01-23T23:01:33+00:00

Re: How to make black and white image?

Postby Werty » 2014-06-18T18:01:54+00:00

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.
Windows 7 user
Werty
 
Posts: 58
Joined: 2010-08-06T05:37:36+00:00

Re: How to make black and white image?

Postby fmw42 » 2014-06-18T18:18:07+00:00

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.
User avatar
fmw42
 
Posts: 15028
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA


Return to Users

Who is online

Users browsing this forum: Google [Bot] and 13 guests