如何用matlab把RAW格式图像提取并转换成灰度图像?

Y = 0.21 R + 0.72 G 0.07 BY
给了个公式
小弟是初学者,有很多问题,恳请大家帮忙!
Y=0.21r+0.72g+0,07b
上面那个公式错了
谢谢您的帮助,就是原始的raw数据,老师就是想让我们自己来编方法所以不让我们用直接读的函数,下面是他给的一些允许用的函数,您帮忙看看给点建议,我还是不知道该怎么实现
图像是400*300,,24bit的
function G = readraw(filename)
%readraw - read RAW format grey scale image of square size into matrix G
% Usage: G = readraw(filename)
disp([' Retrieving Image ' filename ' ...']);
% Get file ID for file
fid=fopen(filename,'rb');
% Check if file exists
if (fid == -1)
error('can not open input image file press CTRL-C to exit \n');
pause
end
% Get all the pixels from the image
pixel = fread(fid, inf, 'uchar');
% Close file
fclose(fid);
% Calculate length/width, assuming image is square
[Y X]=size(pixel);
Size=(Y*X);
N=sqrt(Size);
% Construct matrix
G = zeros(N,N);
% Write pixels into matrix
G(1:Size) = pixel(1:Size);
% Transpose matrix, to orient it properly
G = G';
end %function

如果本身是RAW数据而非RGB的话,就需要先插值,然后用你的那个公式求得灰度图
或者直接使用matlab自带的函数
gray=rgb2gray(I);追问

谢谢您的帮助,我在问题补充里增加的一些内容,麻烦您帮忙看看好吗

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-09-25
如果本身是RAW数据而非RGB的话,
就需要先插值,
然后用那个公式求得灰度图
或者直接使用matlab自带的函数
gray=rgb2gray(I);
相似回答