Convert RGB to Grayscale in ImageMagick command-line

依然范特西╮ 提交于 2019-11-29 21:15:32

convert <img_in> -set colorspace Gray -separate -average <img_out> gives the best result for any image for me.

Using the (r+g+b)/3 method will apply the effects of grayscale, but the image will remain in sRGB (which is the expected behavior for this method). You'll need to specify the desired colorspace along with the -fx command.

convert test.png -fx '(r+g+b)/3' -colorspace Gray gray_fx_average.png

Verify with identify -format "%[colorspace] <== %f\n" gray_fx_average.png

Gray <== gray_fx_average.png

To batch convert images in Fish shell:

for file in *.jpg; convert -colorspace Gray $file $file; end;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!