Grayscale Images with ImageMagick
Grayscale Images with ImageMagick
- author
-
akeil
- date
-
2014-05-10
- version
-
2
Converting a photo to a grayscale version is simple enough with the ImageMagick 1
convert
command:
$ convert photo.jpg -colorspace Gray out.jpg
However, the result leaves something to be desired. It looks "flat" and boring. Better results can be achieved with this command:
$ convert photo.jpg -type Grayscale out.jpg
If you want more control, use parameters to increase contrast. To make the best use of the available range from pure black to pure white, one can stretch contrast. That means the lightest pixels are converted to white and the darkest pixels to black. The other colors are distributed among the available range.
The -linear-stretch
option allows a threshold parameter
which defines the number of pixels that are allowed to be converted to pure
white an d pure black. A higher threshold means that have a greater range of
values to depict the midtones at the expense of details in the highlights
and/or shadows.
$ convert photo.jpg -linear-stretch 1x1 -colorspace Rec709Luma out.jpg