在ImageMagick命令行中将RGB转换为灰度

在ImageMagick命令行中将RGB转换为灰度

本文介绍了在ImageMagick命令行中将RGB转换为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用(r + g + b)/ 3方法将RGB图像(3个通道)转换为灰度图像?
我查看示例页面:
但是所需的方法:

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/#grayscalebut the desired method:

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

给了我一个错误的结果 - 结果图像仍有3个频道。

gave me a wrong result - the resulted image has still 3 channels.

您可以通过运行命令来检查:识别-format%[colorspace]< ==%f \\ \\ n* .png

You can check this by running a command: identify -format "%[colorspace] <== %f\n" *.png.

推荐答案

转换< img_in> -set colorspace Gray -separate -average< img_out> 为我的任何图像提供最佳结果。

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

这篇关于在ImageMagick命令行中将RGB转换为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:51