本文介绍了在没有rgb2gray的情况下在MATLAB中将彩色图像转换为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的彩色图像转换为灰度,并避免使用 rgb2gray
命令。
I want convert my color image to grayscale and avoid to use rgb2gray
command.
推荐答案
那么:
I_grey = mean(I_colour, 3);
您可能需要将其投射到 uint8
然后才能查看它:
It's possible you then might need to cast it to a uint8
before you can view it:
I_grey = uint8(mean(I_colour, 3));
或者如果你想要真正准确,你应该找到加权平均值。有关加权选项,请参阅此问题的答案:
Or if you want to be really accurate you should actually be finding a weighted average. See the answer to this question for weighting options: Formula to determine brightness of RGB color
这是一个例子:
W = permute([0.3086, 0.6094, 0.0820], [3,1,2]);
I_grey = uint8(sum(bsxfun(@times, double(I_colour), W),3));
这篇关于在没有rgb2gray的情况下在MATLAB中将彩色图像转换为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!