Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert an image to grayscale via the command line? [closed]

How can I use sips, imagemagic, or another tool to convert an image to black and white (grayscale) via the command line?

like image 720
cwd Avatar asked Oct 10 '11 03:10

cwd


People also ask

How do you convert an image to grayscale in image processing?

In MATLAB, there is a function called rgb2gray() is available to convert RGB image to grayscale image. Here we will convert an RGB image to grayscale image without using rgb2gray() function.

What code would you write to convert the image to grayscale?

Convert an Image to Grayscale in Python Using the Conversion Formula and the Matplotlib Library. We can also convert an image to grayscale using the standard RGB to grayscale conversion formula that is imgGray = 0.2989 * R + 0.5870 * G + 0.1140 * B .

How do I make an image grayscale in RGB?

You just have to take the average of three colors. Since its an RGB image, so it means that you have add r with g with b and then divide it by 3 to get your desired grayscale image. Its done in this way.


2 Answers

If you have imagemagick installed,

convert source.jpg -colorspace Gray destination.jpg (true grayscale only) convert source.jpg -monochrome destination.jpg (true black and white) convert source.jpg -separate destination.jpg (separate into gray channels) 

If you don't care about losing the original file: mogrify -colorspace Gray file.

like image 96
mark Avatar answered Sep 20 '22 14:09

mark


use one of: -monochrome or -colorspace gray options for imagemagick (convert).

like image 29
imm Avatar answered Sep 18 '22 14:09

imm