Convert RGB to Grayscale in ImageMagick command-line

前端 未结 7 1049
孤街浪徒
孤街浪徒 2020-12-23 16:16

How do I convert a RGB image (3 channels) to a grayscale one, using the (r+g+b)/3 method? I look through an examples page: http://www.imagemagick.org/Usage/color_mods/#grays

7条回答
  •  甜味超标
    2020-12-23 16:28

    A few ways to that in Imagemagick command line are:

    convert test.png -grayscale average gray_average.png
    
    or
    
    convert test.png -colorspace OHTA -channel r -separate +channel gray_average.png
    
    or
    
    convert test.png -intensity average -colorspace gray gray_average.png
    
    or
    
    convert test.png -colorspace HSI -channel blue -separate +channel gray_average.png
    


    See

    https://imagemagick.org/script/command-line-options.php#grayscale https://imagemagick.org/script/command-line-options.php#intensity https://imagemagick.org/script/command-line-options.php#colorspace

提交回复
热议问题